From 4c7d95f001b86425722a7898fbeffbfb8d9148a5 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 12 Mar 2021 08:45:41 +0100 Subject: [PATCH] Requested changes + e2e updated --- e2e/paths/12-entry/03_latestBuys.spec.js | 2 +- .../methods/entry/specs/importBuys.spec.js | 16 ++++++++------ .../entry/specs/importBuysPreview.spec.js | 3 ++- modules/entry/front/buy/import/index.spec.js | 21 +++++++++++++++++-- modules/entry/front/latest-buys/index.html | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/e2e/paths/12-entry/03_latestBuys.spec.js b/e2e/paths/12-entry/03_latestBuys.spec.js index 8e9de8158..f2d64e3b4 100644 --- a/e2e/paths/12-entry/03_latestBuys.spec.js +++ b/e2e/paths/12-entry/03_latestBuys.spec.js @@ -41,6 +41,6 @@ describe('Entry lastest buys path', () => { it('should navigate to the entry.buy section by clicking one of the buys', async() => { await page.waitToClick(selectors.entryLatestBuys.firstBuy); - await page.waitForState('entry.card.buy'); + await page.waitForState('entry.card.buy.index'); }); }); diff --git a/modules/entry/back/methods/entry/specs/importBuys.spec.js b/modules/entry/back/methods/entry/specs/importBuys.spec.js index 06fb46d3a..d0793a2f6 100644 --- a/modules/entry/back/methods/entry/specs/importBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuys.spec.js @@ -20,11 +20,13 @@ describe('entry import()', () => { }); it('should import the buy rows', async() => { + const expectedRef = '1, 2'; + const expectedObservation = '123456'; const ctx = { req: activeCtx, args: { - observation: '123456', - ref: '1, 2', + observation: expectedObservation, + ref: expectedRef, buys: [ { itemFk: 1, @@ -33,7 +35,8 @@ describe('entry import()', () => { grouping: 1, packing: 1, size: 1, - volume: 1200 + volume: 1200, + packageFk: '94' }, { itemFk: 4, @@ -42,7 +45,8 @@ describe('entry import()', () => { grouping: 1, packing: 1, size: 25, - volume: 1125 + volume: 1125, + packageFk: '94' } ] } @@ -66,8 +70,8 @@ describe('entry import()', () => { where: {entryFk: newEntry.id} }, options); - expect(updatedEntry.observation).toEqual('123456'); - expect(updatedEntry.ref).toEqual('1, 2'); + expect(updatedEntry.observation).toEqual(expectedObservation); + expect(updatedEntry.ref).toEqual(expectedRef); expect(entryBuys.length).toEqual(2); // Restores diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index db7776781..d286993ad 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -12,6 +12,7 @@ describe('entry importBuysPreview()', () => { }); it('should return the buys with the calculated packageFk', async() => { + const expectedPackageFk = '3'; const buys = [ { itemFk: 1, @@ -35,6 +36,6 @@ describe('entry importBuysPreview()', () => { const randomIndex = Math.floor(Math.random() * result.length); const buy = result[randomIndex]; - expect(buy.packageFk).toEqual('3'); + expect(buy.packageFk).toEqual(expectedPackageFk); }); }); diff --git a/modules/entry/front/buy/import/index.spec.js b/modules/entry/front/buy/import/index.spec.js index e7428e8be..126c7375f 100644 --- a/modules/entry/front/buy/import/index.spec.js +++ b/modules/entry/front/buy/import/index.spec.js @@ -97,6 +97,23 @@ describe('Entry', () => { }); describe('onSubmit()', () => { + it(`should throw an error when some of the rows doesn't have an item`, () => { + jest.spyOn(controller.vnApp, 'showError'); + + controller.import = { + observation: '123456', + ref: '1, 2', + buys: [ + {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, + {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} + ] + }; + + controller.onSubmit(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`Some of the imported buys doesn't have an item`); + }); + it(`should perform a query to update columns`, () => { jest.spyOn(controller.vnApp, 'showSuccess'); controller.$state.go = jest.fn(); @@ -105,8 +122,8 @@ describe('Entry', () => { observation: '123456', ref: '1, 2', buys: [ - {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, - {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} + {'itemFk': 10, 'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, + {'itemFk': 11, 'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} ] }; const params = controller.import; diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 34f6464fc..3b6143e76 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -61,7 +61,7 @@ + ui-sref="entry.card.buy.index({id: {{::buy.entryFk}}})">