This commit is contained in:
parent
84e6e7f7bf
commit
26c74a3e71
|
@ -102,11 +102,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter, options) => {
|
Self.filter = async(ctx, filter, options) => {
|
||||||
const userId = ctx?.req?.accessToken?.userId;
|
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 models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const models = require('vn-loopback/server/server').models;
|
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() => {
|
it('should return 1 result filtering by id', async() => {
|
||||||
const tx = await app.models.Claim.beginTransaction({});
|
const tx = await app.models.Claim.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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.length).toEqual(1);
|
||||||
expect(result[0].id).toEqual(1);
|
expect(result[0].id).toEqual(1);
|
||||||
|
@ -26,7 +36,7 @@ fdescribe('claim filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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.length).toEqual(1);
|
||||||
expect(result[0].id).toEqual(4);
|
expect(result[0].id).toEqual(4);
|
||||||
|
@ -44,7 +54,7 @@ fdescribe('claim filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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.length).toEqual(4);
|
||||||
expect(result[0].id).toEqual(1);
|
expect(result[0].id).toEqual(1);
|
||||||
|
@ -65,7 +75,7 @@ fdescribe('claim filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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.length).toEqual(3);
|
||||||
expect(result[0].id).toEqual(1);
|
expect(result[0].id).toEqual(1);
|
||||||
|
@ -85,7 +95,7 @@ fdescribe('claim filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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.length).toEqual(3);
|
||||||
expect(result[0].id).toEqual(2);
|
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({});
|
const tx = await models.Claim.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}};
|
|
||||||
const filter = {};
|
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);
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue