WIP: fix: refs #7917 fix methods, tests, acls #3085

Draft
carlossa wants to merge 12 commits from 7917-freelancerRoute into dev
1 changed files with 35 additions and 31 deletions
Showing only changes of commit 0c4985604b - Show all commits

View File

@ -2,17 +2,9 @@ const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('AgencyTerm filter()', () => { describe('AgencyTerm filter()', () => {
const authUserId = 9;
let ctx;
const today = Date.vnNew(); const today = Date.vnNew();
today.setHours(2, 0, 0, 0); today.setHours(2, 0, 0, 0);
beforeAll(async() => { let ctx = beforeAll.getCtx();
ctx = {
args: {
ctx: {req: {accessToken: {userId: authUserId}}},
}
};
});
it('should return all results matching the filter', async() => { it('should return all results matching the filter', async() => {
const tx = await models.AgencyTerm.beginTransaction({}); const tx = await models.AgencyTerm.beginTransaction({});
@ -35,26 +27,33 @@ describe('AgencyTerm filter()', () => {
}); });
it('should return results matching "search" searching by integer', async() => { it('should return results matching "search" searching by integer', async() => {
ctx = { // ctx = {
args: { // args: {
search: 1, // search: 1,
} // }
// };
const filter = {
order: 'isActive ASC, name',
search: 1
}; };
let result = await app.models.AgencyTerm.filter(ctx); let result = await app.models.AgencyTerm.filter(ctx, filter);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(1); expect(result[0].routeFk).toEqual(1);
}); });
it('should return results matching "search" searching by string', async() => { it('should return results matching "search" searching by string', async() => {
ctx = { // ctx = {
args: { // args: {
search: 'Plants SL', // search: 'Plants SL',
} // }
// };
const filter = {
search: 'Plants SL'
}; };
let result = await app.models.AgencyTerm.filter(ctx); let result = await app.models.AgencyTerm.filter(ctx, filter);
expect(result.length).toEqual(2); expect(result.length).toEqual(2);
}); });
@ -82,26 +81,31 @@ describe('AgencyTerm filter()', () => {
}); });
it('should return results matching "agencyModeFk"', async() => { it('should return results matching "agencyModeFk"', async() => {
ctx = { // ctx = {
args: { // args: {
agencyModeFk: 1, // agencyModeFk: 1,
} // }
// };
const filter = {
agencyModeFk: 1,
}; };
let result = await app.models.AgencyTerm.filter(ctx, filter);
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(1); expect(result[0].routeFk).toEqual(1);
}); });
it('should return results matching "agencyFk"', async() => { it('should return results matching "agencyFk"', async() => {
ctx = { // ctx = {
args: { // args: {
agencyFk: 2, // agencyFk: 2,
} // }
}; // };
let result = await app.models.AgencyTerm.filter(ctx); const filter = {
agencyFk: 2
};
let result = await app.models.AgencyTerm.filter(ctx, filter);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(2); expect(result[0].routeFk).toEqual(2);