Added conditional and test

This commit is contained in:
jorgebl 2021-02-22 09:53:03 +01:00
parent 0732ff38b1
commit 5692b5f07e
3 changed files with 20 additions and 2 deletions

View File

@ -31,7 +31,7 @@ module.exports = Self => {
t.warehouseInFk, t.warehouseInFk,
t.warehouseOutFk, t.warehouseOutFk,
t.landed, t.landed,
t.shipped,+ t.shipped,
t.agencyFk t.agencyFk
FROM travel t FROM travel t
WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]);
@ -43,6 +43,7 @@ module.exports = Self => {
WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration
FROM tmp.travel t FROM tmp.travel t
WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`);
let resultAvgDays = stmts.push(stmt) - 1; let resultAvgDays = stmts.push(stmt) - 1;
stmts.push( stmts.push(
`DROP TEMPORARY TABLE `DROP TEMPORARY TABLE
@ -52,6 +53,7 @@ module.exports = Self => {
let result = await conn.executeStmt(sql); let result = await conn.executeStmt(sql);
avgDays = result[resultAvgDays]; avgDays = result[resultAvgDays];
return avgDays; return avgDays;
}; };
}; };

View File

@ -22,6 +22,8 @@ class Controller extends Section {
agencyModeFk: this.travel.agencyModeFk agencyModeFk: this.travel.agencyModeFk
}; };
this.$http.get(query, {params}).then(res => { this.$http.get(query, {params}).then(res => {
if (res.data.length < 1)
return;
const landed = new Date(value); const landed = new Date(value);
const futureDate = landed.getDate() + res.data[0].dayDuration; const futureDate = landed.getDate() + res.data[0].dayDuration;
landed.setDate(futureDate); landed.setDate(futureDate);

View File

@ -41,7 +41,7 @@ describe('Travel Component vnTravelCreate', () => {
}); });
}); });
describe('onShippedChange()', () => { fdescribe('onShippedChange()', () => {
it(`should do nothing if there's no agencyModeFk in the travel.`, () => { it(`should do nothing if there's no agencyModeFk in the travel.`, () => {
controller.travel = {}; controller.travel = {};
controller.onShippedChange(); controller.onShippedChange();
@ -51,6 +51,20 @@ describe('Travel Component vnTravelCreate', () => {
expect(controller.travel.warehouseOutFk).toBeUndefined(); 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.`, () => { it(`should fill the fields when it's selected a date and agency.`, () => {
controller.travel = {agencyModeFk: 1}; controller.travel = {agencyModeFk: 1};
const tomorrow = new Date(); const tomorrow = new Date();