From 26c74a3e71b321bb0c5d35768dcb47581a95860f Mon Sep 17 00:00:00 2001 From: jcasado Date: Mon, 8 Apr 2024 13:03:15 +0200 Subject: [PATCH] refs #6641 fix test --- modules/claim/back/methods/claim/filter.js | 6 +---- .../back/methods/claim/specs/filter.spec.js | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js index 21d6ff80f..56d4fdfed 100644 --- a/modules/claim/back/methods/claim/filter.js +++ b/modules/claim/back/methods/claim/filter.js @@ -102,11 +102,7 @@ module.exports = Self => { }); Self.filter = async(ctx, filter, options) => { - const userId = ctx?.req?.accessToken?.userId; - console.log('ctx', ctx); - console.log('ctx.req', ctx.req); - console.log('ctx.req.accessToken', ctx.req.accessToken); - console.log('ctx.req.accessToken.userId', ctx.req.accessToken.userId); + const userId = ctx.req.accessToken.userId; const models = Self.app.models; const conn = Self.dataSource.connector; const args = ctx.args; diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index 677015c4d..08e680e97 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -1,14 +1,24 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; -fdescribe('claim filter()', () => { +describe('claim filter()', () => { + let ctx; + beforeEach(() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + } + }; + }); + it('should return 1 result filtering by id', async() => { const tx = await app.models.Claim.beginTransaction({}); try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, search: 1}}, null, options); + const result = await app.models.Claim.filter({...ctx, args: {filter: {}, search: 1}}, null, options); expect(result.length).toEqual(1); expect(result[0].id).toEqual(1); @@ -26,7 +36,7 @@ fdescribe('claim filter()', () => { try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options); + const result = await app.models.Claim.filter({...ctx, args: {filter: {}, search: 'Tony Stark'}}, null, options); expect(result.length).toEqual(1); expect(result[0].id).toEqual(4); @@ -44,7 +54,7 @@ fdescribe('claim filter()', () => { try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, workerFk: 18}}, null, options); + const result = await app.models.Claim.filter({...ctx, args: {filter: {}, workerFk: 18}}, null, options); expect(result.length).toEqual(4); expect(result[0].id).toEqual(1); @@ -65,7 +75,7 @@ fdescribe('claim filter()', () => { try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, itemFk: 2}}, null, options); + const result = await app.models.Claim.filter({...ctx, args: {filter: {}, itemFk: 2}}, null, options); expect(result.length).toEqual(3); expect(result[0].id).toEqual(1); @@ -85,7 +95,7 @@ fdescribe('claim filter()', () => { try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, claimResponsibleFk: 7}}, null, options); + const result = await app.models.Claim.filter({...ctx, args: {filter: {}, claimResponsibleFk: 7}}, null, options); expect(result.length).toEqual(3); expect(result[0].id).toEqual(2); @@ -99,15 +109,14 @@ fdescribe('claim filter()', () => { } }); - it('should now return the tickets from the worker team', async() => { + it('should now return claims from the worker team', async() => { const tx = await models.Claim.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}}; const filter = {}; - const result = await models.Claim.filter(ctx, filter, options); + const result = await models.Claim.filter({...ctx, args: {filter: {}, itemFk: null, myTeam: true}}, filter, options); expect(result.length).toEqual(2);