From 94a2d3cc163e9be218f1b852cf310a6de4db6572 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Jan 2022 14:49:22 +0100 Subject: [PATCH] refactor(supplier): add isFarmer in getSummary --- modules/supplier/back/methods/supplier/getSummary.js | 5 +++++ .../back/methods/supplier/specs/getSummary.spec.js | 8 ++++++++ modules/supplier/front/summary/index.js | 8 -------- modules/supplier/front/summary/index.spec.js | 12 ------------ 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/supplier/back/methods/supplier/getSummary.js b/modules/supplier/back/methods/supplier/getSummary.js index d51f84947..67f5267b6 100644 --- a/modules/supplier/back/methods/supplier/getSummary.js +++ b/modules/supplier/back/methods/supplier/getSummary.js @@ -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; }; }; diff --git a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js index 30713f517..21e56882f 100644 --- a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js +++ b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js @@ -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); + }); }); diff --git a/modules/supplier/front/summary/index.js b/modules/supplier/front/summary/index.js index 85268a13d..a828379bc 100644 --- a/modules/supplier/front/summary/index.js +++ b/modules/supplier/front/summary/index.js @@ -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', { diff --git a/modules/supplier/front/summary/index.spec.js b/modules/supplier/front/summary/index.spec.js index e8ab74220..aa44cd14f 100644 --- a/modules/supplier/front/summary/index.spec.js +++ b/modules/supplier/front/summary/index.spec.js @@ -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}); - }); }); }); });