refs #6436 feat: use mocks
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-04-01 11:00:55 +02:00
parent d6ee5d571e
commit 8ab9063b50
8 changed files with 17 additions and 101 deletions

View File

@ -1,15 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('collection getTickets()', () => {
let ctx;
beforeAll(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
}
};
});
const {ctx} = beforeAll;
it('should get tickets, sales and barcodes from collection', async() => {
const tx = await models.Collection.beginTransaction({});

View File

@ -1,5 +1,5 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('Client Create', () => {
const newAccount = {
@ -17,18 +17,7 @@ describe('Client Create', () => {
delete newAccountWithoutEmail.email;
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
mockLoopBackContext();
});
it(`should not find Deadpool as he's not created yet`, async() => {

View File

@ -1,24 +1,11 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('invoiceIn corrective()', () => {
let ctx;
const {ctx} = beforeAll;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;

View File

@ -1,26 +1,14 @@
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
// #6276
describe('ItemShelving upsertItem()', () => {
const warehouseFk = 1;
let ctx;
const {ctx} = beforeAll;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;

View File

@ -1,24 +1,15 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
const {mockLoopBackContext, mockBeforeAll} = require('vn-loopback/../../back/vn-jasmine');
describe('Ticket cloning - clone function', () => {
let ctx;
let ctx = mockBeforeAll({ejemploe: true});
let options;
let tx;
beforeAll(async() => {
mockLoopBackContext();
});
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;

View File

@ -1,22 +1,11 @@
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Ticket addSaleByCode()', () => {
const quantity = 3;
const ticketFk = 13;
const warehouseFk = 1;
beforeAll(async() => {
activeCtx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'},
__: value => value
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
const {ctx} = beforeAll;
it('should add a new sale', async() => {
const tx = await models.Ticket.beginTransaction({});
@ -26,7 +15,7 @@ describe('Ticket addSaleByCode()', () => {
const code = '1111111111';
const salesBefore = await models.Sale.find(null, options);
await models.Ticket.addSaleByCode(activeCtx, code, quantity, ticketFk, warehouseFk, options);
await models.Ticket.addSaleByCode(ctx, code, quantity, ticketFk, warehouseFk, options);
const salesAfter = await models.Sale.find(null, options);
expect(salesAfter.length).toEqual(salesBefore.length + 1);

View File

@ -1,26 +1,13 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Ticket cloning - clone function', () => {
let ctx;
const {ctx} = beforeAll;
let options;
let tx;
const ticketId = 1;
const shipped = Date.vnNew();
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.Ticket.beginTransaction({});
options.transaction = tx;

View File

@ -4,18 +4,11 @@ describe('Ticket transferClient()', () => {
const originalTicketId = 8;
const refundTicketId = 24;
const clientId = 1;
let ctx;
const {ctx} = beforeAll;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
options = {transaction: tx};
tx = await models.Ticket.beginTransaction({});
options.transaction = tx;