#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
40 changed files with 116 additions and 121 deletions
Showing only changes of commit 84a51d3e8d - Show all commits

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('setSaleQuantity()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should change quantity sale', async() => {
const tx = await models.Ticket.beginTransaction({});

View File

@ -84,7 +84,10 @@ async function test() {
'loopback/**/*[sS]pec.js',
'modules/*/back/**/*.[sS]pec.js'
],
helpers: [`back/vn-jasmine.js`]
helpers: [`back/vn-jasmine.js`],
asyncHelpers: {miHelperAsync
jon marked this conversation as resolved Outdated

@jon Quitar

@jon Quitar
}
};
if (PARALLEL) {
@ -114,10 +117,14 @@ async function test() {
if (opts.ci)
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = SPEC_TIMEOUT;
// runner.loadConfigFile('back/jasmine.json');
runner.loadConfig(config);
process.env.SPEC_IS_RUNNING = true;
await runner.execute();
}
test();
function miHelperAsync() {
jon marked this conversation as resolved Outdated

@jon Quitar

@jon Quitar
return new Promise((resolve, reject) => {
resolve('Resultado del helper');
});
}

View File

@ -45,4 +45,6 @@ module.exports = {
(function init() {
vnBeforeAll();
describe.$inject = () => {
jon marked this conversation as resolved Outdated

@jon Quitar

@jon Quitar
};
})();

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Model crud()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
jon marked this conversation as resolved Outdated
Outdated
Review

CHECK ALL ==> quitar async y {}

CHECK ALL ==> quitar async y {}
mockLoopBackContext()
);
let insertId;
const barcodeModel = app.models.ItemBarcode;

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Model rewriteDbError()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should extend rewriteDbError properties to any model passed', () => {
const exampleModel = models.ItemTag;

View File

@ -40,9 +40,9 @@ describe('claim regularizeClaim()', () => {
return await models.ClaimEnd.create(claimEnds, options);
}
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should send a chat message with value "Trash" and then change claim state to resolved', async() => {
const tx = await models.Claim.beginTransaction({});

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Update Claim', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const newDate = Date.vnNew();
const original = {
ticketFk: 3,

View File

@ -2,11 +2,12 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Client addressesPropagateRe', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => {
it('should propagate the isEqualizated on both addresses of Mr Wayne' +
' and set hasToInvoiceByAddress to false', async() => {
const tx = await models.Client.beginTransaction({});
try {

View File

@ -7,9 +7,9 @@ describe('Address createAddress', () => {
const incotermsFk = 'FAS';
const customAgentOneId = 1;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should throw a non uee member error if no incoterms is defined', async() => {
const tx = await models.Client.beginTransaction({});

View File

@ -16,9 +16,9 @@ describe('Client Create', () => {
const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount));
delete newAccountWithoutEmail.email;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it(`should not find deadpool as he's not created yet`, async() => {
const tx = await models.Client.beginTransaction({});

View File

@ -14,9 +14,9 @@ describe('Address updateAddress', () => {
}
};
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should throw the non uee member error if no incoterms is defined', async() => {
const tx = await models.Client.beginTransaction({});

View File

@ -5,9 +5,9 @@ describe('loopback model address', () => {
let createdAddressId;
const clientId = 1101;
beforeAll(() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
afterAll(async() => {
const client = await models.Client.findById(clientId);

View File

@ -7,9 +7,9 @@ describe('entry addFromPackaging()', () => {
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should create an incoming travel', async() => {
const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}};

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Buy editLatestsBuys()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should change the value of a given column for the selected buys', async() => {
const tx = await models.Buy.beginTransaction({});

View File

@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('entry importBuysPreview()', () => {
const entryId = 1;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should return the buys with the calculated packagingFk', async() => {
const tx = await models.Entry.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('invoiceInDueDay new()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should correctly create a new due day', async() => {
const userId = 9;

View File

@ -2,9 +2,9 @@ const {models} = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('itemShelving getAlternative()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should return a list of items without alternatives', async() => {
const shelvingFk = 'HEJ';

View File

@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('item clone()', () => {
let nextItemId;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
beforeEach(async() => {
let query = `SELECT i1.id + 1 as id FROM vn.item i1

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('regularize()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should create a new ticket and add a line', async() => {
const tx = await models.Item.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('item updateTaxes()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should throw an error if the taxClassFk is blank', async() => {
const tx = await models.Item.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('tag onSubmit()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should delete a tag', async() => {
const tx = await models.Item.beginTransaction({});

View File

@ -1,11 +1,10 @@
const {mockLoopBackContext} = require('../../../../../../back/vn-jasmine');
const models = require('vn-loopback/server/server').models;
describe('order filter()', () => {
const ctx = {
req: {accessToken: {userId: 9}},
args: {},
params: {}
};
let ctx;
beforeAll(() => ctx = mockLoopBackContext());
it('should call the filter method with a basic search', async() => {
const myCtx = Object.assign({}, ctx);

View File

@ -1,5 +1,4 @@
const models = require('vn-loopback/server/server').models;
// const LoopBackContext = require('loopback-context');
describe('AgencyTerm createInvoiceIn()', () => {
const {ctx} = beforeAll;

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('route clone()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const createdDate = Date.vnNew();
it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => {

View File

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

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('route updateWorkCenter()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const routeId = 1;
it('should set the commission work center if the worker has workCenter', async() => {

View File

@ -1,5 +1,4 @@
const models = require('vn-loopback/server/server').models;
// const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket deleteExpeditions()', () => {
const {ctx} = beforeAll;

View File

@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('sale canEdit()', () => {
const employeeId = 1;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
describe('sale not exists', () => {
it('should return error if sale not exists', async() => {

View File

@ -14,7 +14,6 @@ describe('Ticket cloning - clone function', () => {
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('sale deleteSales()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should throw an error if the ticket of the given sales is not editable', async() => {
const tx = await models.Sale.beginTransaction({});

View File

@ -10,9 +10,9 @@ describe('sale reserve()', () => {
}
};
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should throw an error if the ticket can not be modified', async() => {
const tx = await models.Sale.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket-request confirm()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it(`should throw an error if the item doesn't exist`, async() => {
const tx = await models.TicketRequest.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket-request deny()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should return the denied ticket request', async() => {
const tx = await models.TicketRequest.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('sale updateDiscount()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const originalSaleId = 8;
it('should throw an error if no sales were selected', async() => {

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket model TicketTracking', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
let ticketTrackingId;
afterAll(async() => {

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Travel createThermograph()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const travelId = 3;
const currentUserId = 1102;
const thermographId = '138350-0';

View File

@ -10,9 +10,9 @@ describe('Worker new', () => {
let tx;
let opts;
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
describe('should return error', () => {
beforeEach(async() => {

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('agency clone()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should clone a zone', async() => {
const tx = await models.Zone.beginTransaction({});

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('zone exclusionGeo()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
const zoneId = 1;
const today = Date.vnNew();

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('zone toggleIsIncluded()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
beforeAll(() =>
mockLoopBackContext()
);
it('should return the created location with isIncluded true', async() => {
const tx = await models.Zone.beginTransaction({});