#6436 Definir funcion global que añada ctx #2232

Merged
jon merged 28 commits from 6436_jasmine_beforeAll into dev 2024-07-03 07:56:18 +00:00
11 changed files with 23 additions and 120 deletions
Showing only changes of commit b3fa869757 - Show all commits

View File

@ -1,15 +1,8 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
// const LoopBackContext = require('loopback-context');
describe('getStarredModules()', () => { describe('getStarredModules()', () => {
const {ctx} = beforeAll; const {ctx} = beforeAll;
// beforeEach(() => {
// spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
// active: ctx
// });
// });
it(`should return the starred modules for a given user`, async() => { it(`should return the starred modules for a given user`, async() => {
const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1});
const starredModules = await models.StarredModule.getStarredModules(ctx); const starredModules = await models.StarredModule.getStarredModules(ctx);

View File

@ -1,15 +1,8 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
// const LoopBackContext = require('loopback-context');
describe('setPosition()', () => { describe('setPosition()', () => {
const {ctx} = beforeAll; const {ctx} = beforeAll;
// beforeEach(() => {
// spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
// active: activeCtx
// });
// });
it('should increase the orders module position by replacing it with clients and vice versa', async() => { it('should increase the orders module position by replacing it with clients and vice versa', async() => {
const tx = await models.StarredModule.beginTransaction({}); const tx = await models.StarredModule.beginTransaction({});

View File

@ -1,15 +1,8 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
// const LoopBackContext = require('loopback-context');
describe('toggleStarredModule()', () => { describe('toggleStarredModule()', () => {
const {ctx} = beforeAll; const {ctx} = beforeAll;
// beforeEach(() => {
// spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
// active: activeCtx
// });
// });
it('should create a new starred module and then remove it by calling the method again with same args', async() => { it('should create a new starred module and then remove it by calling the method again with same args', async() => {
const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order'); const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order');
let starredModules = await models.StarredModule.getStarredModules(ctx); let starredModules = await models.StarredModule.getStarredModules(ctx);

View File

@ -2,15 +2,7 @@ const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('claim filter()', () => { describe('claim filter()', () => {
let ctx; const {ctx} = beforeAll;
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({});

View File

@ -1,5 +1,5 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('claim regularizeClaim()', () => { describe('claim regularizeClaim()', () => {
const userId = 18; const userId = 18;
@ -41,17 +41,7 @@ describe('claim regularizeClaim()', () => {
} }
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
}); });
it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { it('should send a chat message with value "Trash" and then change claim state to resolved', async() => {

View File

@ -1,22 +1,11 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
const i18n = require('i18n'); const i18n = require('i18n');
describe('Update Claim', () => { describe('Update Claim', () => {
let url; let url;
let claimStatesMap = {}; let claimStatesMap = {};
beforeAll(async() => { beforeAll(async() => {
url = await app.models.Url.getUrl(); mockLoopBackContext();
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const claimStates = await app.models.ClaimState.find(); const claimStates = await app.models.ClaimState.find();
claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {});
}); });

View File

@ -1,19 +1,9 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Update Claim', () => { describe('Update Claim', () => {
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
}); });
const newDate = Date.vnNew(); const newDate = Date.vnNew();
const original = { const original = {

View File

@ -1,21 +1,8 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); // const LoopBackContext = require('loopback-context');
describe('AgencyTerm createInvoiceIn()', () => { describe('AgencyTerm createInvoiceIn()', () => {
const ctx = {req: {accessToken: {userId: 9}}}; const {ctx} = beforeAll;
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
const rows = [ const rows = [
{ {
routeFk: 2, routeFk: 2,

View File

@ -1,20 +1,9 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('route clone()', () => { describe('route clone()', () => {
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
}); });
const createdDate = Date.vnNew(); const createdDate = Date.vnNew();

View File

@ -1,20 +1,17 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); // const LoopBackContext = require('loopback-context');
describe('route guessPriority()', () => { describe('route guessPriority()', () => {
const targetRouteId = 7; const targetRouteId = 7;
let routeTicketsToRestore; let routeTicketsToRestore;
const activeCtx = { const {ctx} = beforeAll;
accessToken: {userId: 9},
__: () => {}
};
beforeAll(() => { // beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx // active: activeCtx
}); // });
}); // });
afterAll(async() => { afterAll(async() => {
let restoreFixtures = []; let restoreFixtures = [];
@ -25,9 +22,9 @@ describe('route guessPriority()', () => {
}); });
it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => { it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => {
const ctx = { // const ctx = {
req: activeCtx // req: activeCtx
}; // };
routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}});
await app.models.Route.guessPriority(ctx, targetRouteId); await app.models.Route.guessPriority(ctx, targetRouteId);

View File

@ -1,19 +1,9 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('route updateWorkCenter()', () => { describe('route updateWorkCenter()', () => {
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
}); });
const routeId = 1; const routeId = 1;