From 5692b5f07e09436835171d7700dc0abb9783b6e9 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 22 Feb 2021 09:53:03 +0100 Subject: [PATCH] Added conditional and test --- .../travel/back/methods/travel/getAverageDays.js | 4 +++- modules/travel/front/create/index.js | 2 ++ modules/travel/front/create/index.spec.js | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index e56ac21e6..7f6be936e 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -31,7 +31,7 @@ module.exports = Self => { t.warehouseInFk, t.warehouseOutFk, t.landed, - t.shipped,+ + t.shipped, t.agencyFk FROM travel t WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); @@ -43,6 +43,7 @@ module.exports = Self => { WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration FROM tmp.travel t WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); + let resultAvgDays = stmts.push(stmt) - 1; stmts.push( `DROP TEMPORARY TABLE @@ -52,6 +53,7 @@ module.exports = Self => { let result = await conn.executeStmt(sql); avgDays = result[resultAvgDays]; + return avgDays; }; }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index c76728e59..ba5bbd1ff 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -22,6 +22,8 @@ class Controller extends Section { agencyModeFk: this.travel.agencyModeFk }; this.$http.get(query, {params}).then(res => { + if (res.data.length < 1) + return; const landed = new Date(value); const futureDate = landed.getDate() + res.data[0].dayDuration; landed.setDate(futureDate); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index dcb17d494..af1864ffd 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -41,7 +41,7 @@ describe('Travel Component vnTravelCreate', () => { }); }); - describe('onShippedChange()', () => { + fdescribe('onShippedChange()', () => { it(`should do nothing if there's no agencyModeFk in the travel.`, () => { controller.travel = {}; controller.onShippedChange(); @@ -51,6 +51,20 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel.warehouseOutFk).toBeUndefined(); }); + it(`should do nothing if it hasn't value on response data.`, () => { + controller.travel = {agencyModeFk: 4}; + const tomorrow = new Date(); + const result = [{}]; + const expectedResponse = [{}]; + + const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; + $httpBackend.expectGET(query).respond(expectedResponse); + controller.onShippedChange(tomorrow); + $httpBackend.flush(); + + expect(expectedResponse).toEqual(result); + }); + it(`should fill the fields when it's selected a date and agency.`, () => { controller.travel = {agencyModeFk: 1}; const tomorrow = new Date();