QA refactor
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7895af8a54
commit
3af50dfc80
|
@ -9,7 +9,7 @@ module.exports = Self => {
|
|||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
|
@ -21,13 +21,13 @@ module.exports = Self => {
|
|||
Self.getAverageDays = async agencyModeFk => {
|
||||
const conn = Self.dataSource.connector;
|
||||
let stmts = [];
|
||||
let avgDays = {};
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.travel');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE TEMPORARY TABLE tmp.travel (
|
||||
SELECT t.id,
|
||||
SELECT
|
||||
t.id,
|
||||
t.warehouseInFk,
|
||||
t.warehouseOutFk,
|
||||
t.landed,
|
||||
|
@ -37,22 +37,29 @@ module.exports = Self => {
|
|||
WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`SELECT t.id, t.warehouseInFk, t.warehouseOutFk,
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
t.id,
|
||||
t.warehouseInFk,
|
||||
t.warehouseOutFk,
|
||||
(SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped )))
|
||||
FROM tmp.travel t
|
||||
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
|
||||
WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`);
|
||||
WHERE t.agencyFk
|
||||
ORDER BY t.id DESC LIMIT 1`);
|
||||
|
||||
const avgDaysIndex = stmts.push(stmt) - 1;
|
||||
|
||||
let resultAvgDays = stmts.push(stmt) - 1;
|
||||
stmts.push(
|
||||
`DROP TEMPORARY TABLE
|
||||
tmp.travel`);
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
let result = await conn.executeStmt(sql);
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql);
|
||||
|
||||
avgDays = result[resultAvgDays];
|
||||
const [avgDays] = result[avgDaysIndex];
|
||||
|
||||
return avgDays;
|
||||
};
|
||||
|
|
|
@ -22,15 +22,16 @@ class Controller extends Section {
|
|||
agencyModeFk: this.travel.agencyModeFk
|
||||
};
|
||||
this.$http.get(query, {params}).then(res => {
|
||||
if (res.data.length < 1)
|
||||
if (!res.data)
|
||||
return;
|
||||
|
||||
const landed = new Date(value);
|
||||
const futureDate = landed.getDate() + res.data[0].dayDuration;
|
||||
const futureDate = landed.getDate() + res.data.dayDuration;
|
||||
landed.setDate(futureDate);
|
||||
|
||||
this.travel.landed = landed;
|
||||
this.travel.warehouseInFk = res.data[0].warehouseInFk;
|
||||
this.travel.warehouseOutFk = res.data[0].warehouseOutFk;
|
||||
this.travel.warehouseInFk = res.data.warehouseInFk;
|
||||
this.travel.warehouseOutFk = res.data.warehouseOutFk;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -51,15 +51,30 @@ describe('Travel Component vnTravelCreate', () => {
|
|||
expect(controller.travel.warehouseOutFk).toBeUndefined();
|
||||
});
|
||||
|
||||
it(`should do nothing if it hasn't value on response data.`, () => {
|
||||
it(`should do nothing if there's no response data.`, () => {
|
||||
controller.travel = {agencyModeFk: 4};
|
||||
const tomorrow = new Date();
|
||||
const expectedResponse = [{
|
||||
agencyModeFk: 4,
|
||||
warehouseInFk: undefined,
|
||||
warehouseOutFk: undefined,
|
||||
dayDuration: 0
|
||||
}];
|
||||
|
||||
const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`;
|
||||
$httpBackend.expectGET(query).respond(undefined);
|
||||
controller.onShippedChange(tomorrow);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.travel.warehouseInFk).toBeUndefined();
|
||||
expect(controller.travel.warehouseOutFk).toBeUndefined();
|
||||
expect(controller.travel.dayDuration).toBeUndefined();
|
||||
});
|
||||
|
||||
it(`should fill the fields when it's selected a date and agency.`, () => {
|
||||
controller.travel = {agencyModeFk: 1};
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 9);
|
||||
const expectedResponse = {
|
||||
id: 8,
|
||||
dayDuration: 9,
|
||||
warehouseInFk: 5,
|
||||
warehouseOutFk: 1
|
||||
};
|
||||
|
||||
const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`;
|
||||
$httpBackend.expectGET(query).respond(expectedResponse);
|
||||
|
@ -68,27 +83,6 @@ describe('Travel Component vnTravelCreate', () => {
|
|||
|
||||
expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk);
|
||||
expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk);
|
||||
expect(controller.travel.dayDuration).toEqual(expectedResponse.dayDuration);
|
||||
});
|
||||
|
||||
it(`should fill the fields when it's selected a date and agency.`, () => {
|
||||
controller.travel = {agencyModeFk: 1};
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 9);
|
||||
const expectedResponse = [{
|
||||
id: 8,
|
||||
dayDuration: 9,
|
||||
warehouseInFk: 5,
|
||||
warehouseOutFk: 1
|
||||
}];
|
||||
|
||||
const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`;
|
||||
$httpBackend.expectGET(query).respond(expectedResponse);
|
||||
controller.onShippedChange(tomorrow);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.travel.warehouseInFk).toEqual(expectedResponse[0].warehouseInFk);
|
||||
expect(controller.travel.warehouseOutFk).toEqual(expectedResponse[0].warehouseOutFk);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue