diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index d249242a9..925dcdfac 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -38,7 +38,8 @@ module.exports = Self => { case 'search': return {or: [ {'t.id': value}, - {'c.id': value} + {'c.id': value}, + {'c.name': {like: `%${value}%`}} ]}; } }); diff --git a/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js new file mode 100644 index 000000000..14729b094 --- /dev/null +++ b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js @@ -0,0 +1,41 @@ +const app = require('vn-loopback/server/server'); + +describe('ticket-weekly filter()', () => { + const authUserId = 9; + it('should return the tickets matching the filter', async() => { + const ctx = {req: {accessToken: {userId: authUserId}}, args: {}}; + const filter = {order: 'id DESC'}; + const result = await app.models.TicketWeekly.filter(ctx, filter); + const firstRow = result[0]; + + expect(firstRow.ticketFk).toEqual(1); + }); + + it('should return the ticket with id one', async() => { + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 2}}; + const filter = {}; + const result = await app.models.TicketWeekly.filter(ctx, filter); + const firstRow = result[0]; + + expect(firstRow.ticketFk).toEqual(2); + }); + + it('should return the ticket matching the client name', async() => { + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 'bruce'}}; + const filter = {}; + const result = await app.models.TicketWeekly.filter(ctx, filter); + const firstRow = result[0]; + + expect(firstRow.clientName).toEqual('Bruce Wayne'); + }); + + it('should return the ticket matching the client id', async() => { + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 101}}; + const filter = {}; + const result = await app.models.TicketWeekly.filter(ctx, filter); + const firstRow = result[0]; + + expect(firstRow.clientFk).toEqual(101); + expect(firstRow.clientName).toEqual('Bruce Wayne'); + }); +});