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.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;
};
};

View File

@ -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);

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.`, () => {
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();