fix: update SQL fixture values and enhance getVideoList method with transaction handling
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2025-02-12 09:51:56 +01:00
parent 8d0fec4ffd
commit 1c8ad94ab8
3 changed files with 28 additions and 28 deletions

View File

@ -77,8 +77,8 @@ INSERT INTO `vn`.`agency` (`name`, `warehouseFk`, `isOwn`, `isAnyVolumeAllowed`)
('Otra agencia ', '1', '0', '0');
INSERT INTO `vn`.`expedition` (`agencyModeFk`, `ticketFk`, `isBox`, `counter`, `workerFk`, `externalId`, `packagingFk`, `hostFk`, `itemPackingTypeFk`, `hasNewRoute`) VALUES
('1', '1', 1, '1', '1', '1', '1', 'pc00', 'F', 0),
('1', '1', 1, '2', '1', '1', '1', 'pc00', 'F', 0);
('1', '1', 1, '1', '1', '1', '1', 'pc1', 'F', 0),
('1', '1', 1, '2', '1', '1', '1', 'pc1', 'F', 0);
INSERT INTO vn.client (id,name,defaultAddressFk,street,fi,email,dueDay,isTaxDataChecked,accountingAccount,city,provinceFk,postcode,socialName,contact,credit,countryFk,quality,riskCalculated) VALUES
(100,'root',110,'Valle de la muerte','74974747G','root@mydomain.com',0,1,'4300000078','ALGEMESI',1,'46680','rootSocial','rootContact',500.0,1,10,'2025-01-01');

View File

@ -45,11 +45,13 @@ module.exports = Self => {
e.created
FROM expedition e
JOIN host h ON Convert(h.code USING utf8mb3) COLLATE utf8mb3_unicode_ci = e.hostFk
JOIN packingSite ps ON ps.hostFk = h.id
JOIN packingSite ps ON ps.hostFk = h.id
WHERE e.id = ?;`;
const [expedition] = await models.PackingSiteConfig.rawSql(query, [id]);
const [expedition] = await models.PackingSiteConfig.rawSql(query, [id], myOptions);
if (!from && !expedition) return [];
let start = new Date(expedition.created);
let end = new Date(start.getTime() + (packingSiteConfig.avgBoxingTime * 1000));
@ -57,9 +59,13 @@ module.exports = Self => {
start.setHours(from, 0, 0);
end.setHours(to, 0, 0);
}
const offset = start.getTimezoneOffset();
start = new Date(start.getTime() - (offset * 60 * 1000));
end = new Date(end.getTime() - (offset * 60 * 1000));
const minutes = start.getMinutes();
const roundedMinutes = minutes - (minutes % 15);
start.setMinutes(roundedMinutes, 0, 0);
const videoUrl =
`/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${expedition.monitorId}`;
@ -73,6 +79,7 @@ module.exports = Self => {
} catch (e) {
return [];
}
return response.data.videos.map(video => video.filename);
};
};

View File

@ -2,35 +2,28 @@ const models = require('vn-loopback/server/server').models;
const axios = require('axios');
describe('boxing getVideoList()', () => {
it('should return video list', async() => {
const tx = await models.PackingSiteConfig.beginTransaction({});
let tx;
let options;
try {
const options = {transaction: tx};
beforeEach(async() => {
tx = await models.PackingSiteConfig.beginTransaction({});
options = {transaction: tx};
});
const id = 1;
const from = 1;
const to = 2;
afterEach(async() => {
await tx.rollback();
});
const response = {
data: {
videos: [{
id: 1,
filename: 'video1.mp4'
}]
}
};
it('should make the correct API call', async() => {
const expedition = await models.Expedition.findById(15, null, options);
await expedition.updateAttribute('created', '2000-12-01 07:07:00', options);
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response)));
const axiosSpy = spyOn(axios, 'get').and.callThrough();
await models.Boxing.getVideoList(expedition.id, undefined, undefined, options);
const result = await models.Boxing.getVideoList(id, from, to, options);
const expectedStartTime = '2000-12-01T07:00:00';
const calledUrl = axiosSpy.calls.mostRecent().args[0];
expect(result[0]).toEqual(response.data.videos[0].filename);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(calledUrl).toContain(`start=${expectedStartTime}`);
});
});