diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 59730d5929..e68a8a7260 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -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'); diff --git a/modules/ticket/back/methods/boxing/getVideoList.js b/modules/ticket/back/methods/boxing/getVideoList.js index ba989936e5..db68d05063 100644 --- a/modules/ticket/back/methods/boxing/getVideoList.js +++ b/modules/ticket/back/methods/boxing/getVideoList.js @@ -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); }; }; diff --git a/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js b/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js index c6d1a3e07c..82780c5866 100644 --- a/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js +++ b/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js @@ -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}`); }); });