diff --git a/modules/ticket/back/methods/boxing/getVideo.js b/modules/ticket/back/methods/boxing/getVideo.js index cdd46b257..6f471e837 100644 --- a/modules/ticket/back/methods/boxing/getVideo.js +++ b/modules/ticket/back/methods/boxing/getVideo.js @@ -2,7 +2,7 @@ const https = require('https'); module.exports = Self => { Self.remoteMethod('getVideo', { - description: 'Get packing video of ticketId', + description: 'Get packing video', accessType: 'READ', accepts: [ { diff --git a/modules/ticket/back/methods/boxing/getVideoList.js b/modules/ticket/back/methods/boxing/getVideoList.js index be6d48c46..3d45a720d 100644 --- a/modules/ticket/back/methods/boxing/getVideoList.js +++ b/modules/ticket/back/methods/boxing/getVideoList.js @@ -21,7 +21,7 @@ module.exports = Self => { required: false, } ], returns: { - type: ['Object'], + type: ['object'], root: true }, http: { @@ -48,7 +48,7 @@ module.exports = Self => { JOIN packingSite ps ON ps.hostFk = h.id WHERE e.id = ?;`; const [expedition] = await models.PackingSiteConfig.rawSql(query, [id]); - console.log(expedition); + if (!from && !expedition) return []; let start = new Date(expedition.created); let end = new Date(start.getTime() + (packingSiteConfig.avgBoxingTime * 1000)); diff --git a/modules/ticket/back/methods/boxing/specs/getVideo.js b/modules/ticket/back/methods/boxing/specs/getVideo.js deleted file mode 100644 index ad5295f0c..000000000 --- a/modules/ticket/back/methods/boxing/specs/getVideo.js +++ /dev/null @@ -1,69 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -xdescribe('sale canEdit()', () => { - it('should return true if the role is production regardless of the saleTrackings', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const productionUserID = 49; - const ctx = {req: {accessToken: {userId: productionUserID}}}; - - const sales = [{id: 3}]; - - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(true); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return true if the role is not production and none of the sales has saleTracking', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const salesPersonUserID = 18; - const ctx = {req: {accessToken: {userId: salesPersonUserID}}}; - - const sales = [{id: 10}]; - - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(true); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return false if any of the sales has a saleTracking record', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const salesPersonUserID = 18; - const ctx = {req: {accessToken: {userId: salesPersonUserID}}}; - - const sales = [{id: 3}]; - - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(false); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/ticket/back/methods/boxing/specs/getVideoList.js b/modules/ticket/back/methods/boxing/specs/getVideoList.js new file mode 100644 index 000000000..e703f4c03 --- /dev/null +++ b/modules/ticket/back/methods/boxing/specs/getVideoList.js @@ -0,0 +1,35 @@ +const models = require('vn-loopback/server/server').models; +const axios = require('axios'); + +describe('boxing getVideoList()', () => { + it('should return data', async() => { + const tx = await models.PackingSiteConfig.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const params = { + id: 1, + from: 1, + to: 2 + }; + + const response = { + data: { + pipe: () => {}, + on: () => {}, + } + }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response))); + + const result = await models.Sale.canEdit(params, options); + + expect(result).toEqual([]); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});