refactor(supplier): add isFarmer in getSummary
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-01-11 14:49:22 +01:00
parent 4f799d3e00
commit 94a2d3cc16
4 changed files with 13 additions and 20 deletions

View File

@ -101,6 +101,11 @@ module.exports = Self => {
]
};
let supplier = await Self.app.models.Supplier.findOne(filter);
const farmerCode = 2;
if (supplier.sageWithholdingFk == farmerCode)
supplier.isFarmer = true;
return supplier;
};
};

View File

@ -25,4 +25,12 @@ describe('Supplier getSummary()', () => {
expect(payMethod.name).toEqual('PayMethod one');
});
it(`should get if supplier is farmer by sageWithholdingFk`, async() => {
const supplier = await app.models.Supplier.findById(2);
const supplierSummary = await app.models.Supplier.getSummary(2);
expect(supplier.isFarmer).toBeUndefined();
expect(supplierSummary.isFarmer).toEqual(true);
});
});

View File

@ -17,16 +17,8 @@ class Controller extends Summary {
getSummary() {
return this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => {
this.summary = response.data;
this.isFarmer(response.data.sageWithholdingFk);
});
}
isFarmer(sageWithholdingFk) {
const farmerCode = 2;
if (sageWithholdingFk == farmerCode)
this.summary.isFarmer = true;
}
}
ngModule.vnComponent('vnSupplierSummary', {

View File

@ -27,18 +27,6 @@ describe('Supplier', () => {
expect(controller.summary).toEqual({id: 1});
});
it('should get if supplier is farmer by sageWithholdingFk', () => {
controller.supplier = {id: 2, sageWithholdingFk: 2};
const query = `Suppliers/${controller.supplier.id}/getSummary`;
$httpBackend.expectGET(query).respond({id: 2, sageWithholdingFk: 2});
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual({id: 2, isFarmer: true, sageWithholdingFk: 2});
});
});
});
});