diff --git a/modules/agency/back/methods/agency/getLanded.js b/modules/agency/back/methods/agency/getLanded.js index 978f639a6..1cadfa76c 100644 --- a/modules/agency/back/methods/agency/getLanded.js +++ b/modules/agency/back/methods/agency/getLanded.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('getLanded', { - description: 'Returns the first shipped and landed possible for params', + description: 'Returns the landed', accessType: 'READ', accepts: [{ arg: 'params', diff --git a/modules/agency/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/agency/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js new file mode 100644 index 000000000..dfa13547b --- /dev/null +++ b/modules/agency/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -0,0 +1,34 @@ +const app = require('vn-loopback/server/server'); + +describe('Agency getAgenciesWithWarehouse()', () => { + const today = new Date(); + it('should return the agencies that can handle the given delivery request', async() => { + let filter = { + addressFk: 101, + landed: today, + warehouseFk: 1 + }; + + let result = await app.models.Agency.getAgenciesWithWarehouse(filter); + let agencies = result[0]; + + expect(agencies.length).toEqual(4); + expect(agencies[0].agency).toEqual('inhouse pickup'); + expect(agencies[1].agency).toEqual('Super-Man delivery'); + expect(agencies[2].agency).toEqual('Silla247'); + expect(agencies[3].agency).toEqual('Silla247Expensive'); + }); + + it('should return no agencies if the date is incorrect', async() => { + let filter = { + addressFk: 101, + landed: null, + warehouseFk: 1 + }; + + let result = await app.models.Agency.getAgenciesWithWarehouse(filter); + let agencies = result[0]; + + expect(agencies.length).toEqual(0); + }); +}); diff --git a/modules/agency/back/methods/agency/specs/getFirstShipped.spec.js b/modules/agency/back/methods/agency/specs/getFirstShipped.spec.js new file mode 100644 index 000000000..3a7c7047d --- /dev/null +++ b/modules/agency/back/methods/agency/specs/getFirstShipped.spec.js @@ -0,0 +1,16 @@ +const app = require('vn-loopback/server/server'); + +describe('Agency getFirstShipped()', () => { + it('should return the first shipped and landed possible for the filter', async() => { + let filter = { + agencyModeFk: 1, + addressFk: 101, + warehouseFk: 1 + }; + + let result = await app.models.Agency.getFirstShipped(filter); + + expect(result.vShipped).toBeDefined(); + expect(result.vLanded).toBeDefined(); + }); +}); diff --git a/modules/agency/back/methods/agency/specs/getLanded.spec.js b/modules/agency/back/methods/agency/specs/getLanded.spec.js new file mode 100644 index 000000000..dad471ce1 --- /dev/null +++ b/modules/agency/back/methods/agency/specs/getLanded.spec.js @@ -0,0 +1,17 @@ +const app = require('vn-loopback/server/server'); + +describe('Agency getLanded()', () => { + const today = new Date(); + it('should return the landed', async() => { + let filter = { + shipped: today, + addressFk: 101, + agencyModeFk: 1, + warehouseFk: 1 + }; + + let result = await app.models.Agency.getLanded(filter); + + expect(result).toEqual(jasmine.any(Date)); + }); +}); diff --git a/modules/agency/back/methods/agency/specs/getShipped.spec.js b/modules/agency/back/methods/agency/specs/getShipped.spec.js new file mode 100644 index 000000000..d291deca7 --- /dev/null +++ b/modules/agency/back/methods/agency/specs/getShipped.spec.js @@ -0,0 +1,16 @@ +const app = require('vn-loopback/server/server'); + +describe('Agency getShipped()', () => { + const today = new Date(); + it('should return the first shipped possible for params', async() => { + let filter = { + landed: today, + addressFk: 101, + agencyModeFk: 1, + }; + + let result = await app.models.Agency.getShipped(filter); + + expect(result).toEqual(jasmine.any(Date)); + }); +}); diff --git a/modules/agency/back/methods/agency/specs/landsThatDay.spec.js b/modules/agency/back/methods/agency/specs/landsThatDay.spec.js new file mode 100644 index 000000000..5b73f14de --- /dev/null +++ b/modules/agency/back/methods/agency/specs/landsThatDay.spec.js @@ -0,0 +1,20 @@ +const app = require('vn-loopback/server/server'); + +describe('Agency landsThatDay()', () => { + const today = new Date(); + it('should return a list of agencies that can land a shipment on a day for an address', async() => { + let filter = { + addressFk: 101, + landed: today, + }; + + let result = await app.models.Agency.landsThatDay(filter); + let agencies = result[0]; + + expect(agencies.length).toEqual(4); + expect(agencies[0].agency).toEqual('inhouse pickup'); + expect(agencies[1].agency).toEqual('Super-Man delivery'); + expect(agencies[2].agency).toEqual('Silla247'); + expect(agencies[3].agency).toEqual('Silla247Expensive'); + }); +}); diff --git a/modules/invoiceOut/back/methods/invoiceOut/filter.js b/modules/invoiceOut/back/methods/invoiceOut/filter.js index e9f60473a..3ac67685b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/filter.js +++ b/modules/invoiceOut/back/methods/invoiceOut/filter.js @@ -71,7 +71,7 @@ module.exports = Self => { } }); - Self.filter = async(ctx, filter) => { + Self.filter = async ctx => { let conn = Self.dataSource.connector; let where = buildFilter(ctx.args, (param, value) => { @@ -95,7 +95,7 @@ module.exports = Self => { } }); - filter = mergeFilters(ctx.args.filter, {where}); + let filter = mergeFilters(ctx.args.filter, {where}); let stmts = []; let stmt; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js new file mode 100644 index 000000000..7091b8843 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js @@ -0,0 +1,111 @@ +const app = require('vn-loopback/server/server'); + +describe('InvoiceOut filter()', () => { + let today = new Date(); + today.setHours(2, 0, 0, 0); + + it('should return the invoice out matching ref', async() => { + let ctx = { + args: { + search: 'T4444444', + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].ref).toEqual('T4444444'); + }); + + it('should return the invoice out matching clientFk', async() => { + let ctx = { + args: { + clientFk: 102, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].ref).toEqual('T2222222'); + }); + + it('should return the invoice out matching hasPdf', async() => { + let ctx = { + args: { + hasPdf: true, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + expect(result.length).toEqual(5); + }); + + it('should return the invoice out matching amount', async() => { + let ctx = { + args: { + amount: 208.35, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + + expect(result.length).toEqual(1); + expect(result[0].ref).toEqual('T2222222'); + }); + + it('should return the invoice out matching min and max', async() => { + let ctx = { + args: { + min: 20.10, + max: 200, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + + expect(result.length).toEqual(2); + }); + + it('should return the invoice out matching issued', async() => { + let ctx = { + args: { + issued: today, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + + expect(result.length).toEqual(1); + }); + + it('should return the invoice out matching created', async() => { + let ctx = { + args: { + created: today, + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + + expect(result.length).toEqual(5); + }); + + it('should return the invoice out matching dued', async() => { + let ctx = { + args: { + dued: today + } + }; + + let result = await app.models.InvoiceOut.filter(ctx); + + + expect(result.length).toEqual(1); + }); +}); diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 05cd87ca2..4b44a39b1 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -65,7 +65,7 @@ module.exports = Self => { } }); - Self.filter = async(ctx, filter) => { + Self.filter = async ctx => { let conn = Self.dataSource.connector; let where = buildFilter(ctx.args, (param, value) => { @@ -89,7 +89,7 @@ module.exports = Self => { } }); - filter = mergeFilters(ctx.args.filter, {where}); + let filter = mergeFilters(ctx.args.filter, {where}); let stmts = []; let stmt; diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js new file mode 100644 index 000000000..805161e9b --- /dev/null +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -0,0 +1,121 @@ +const app = require('vn-loopback/server/server'); + +describe('Route filter()', () => { + let today = new Date(); + today.setHours(2, 0, 0, 0); + + it('should return the routes matching "search"', async() => { + let ctx = { + args: { + search: 1, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(1); + }); + + it('should return the routes matching "from"', async() => { + let ctx = { + args: { + from: today, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(7); + }); + + it('should return the routes matching "to"', async() => { + let ctx = { + args: { + to: today, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(7); + }); + + it('should return the routes matching "m3"', async() => { + let ctx = { + args: { + m3: 4.2, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + }); + + it('should return the routes matching "description"', async() => { + let ctx = { + args: { + description: 'third route', + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + }); + + it('should return the routes matching "workerFk"', async() => { + let ctx = { + args: { + workerFk: 56, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(5); + }); + + it('should return the routes matching "warehouseFk"', async() => { + let ctx = { + args: { + warehouseFk: 1, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(7); + + ctx.args.warehouseFk = 2; + + result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(0); + }); + + it('should return the routes matching "vehicleFk"', async() => { + let ctx = { + args: { + vehicleFk: 2, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + }); + + it('should return the routes matching "agencyModeFk"', async() => { + let ctx = { + args: { + agencyModeFk: 1, + } + }; + + let result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(2); + }); +});