feat: refs #6436 new test changes, rollback order/filter and /ticket/clone
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jon Elias 2024-06-12 08:25:50 +02:00
parent 944355d54f
commit 2b45c2c61a
9 changed files with 36 additions and 72 deletions

View File

@ -2,18 +2,9 @@ const models = require('vn-loopback/server/server').models;
describe('Application execute()/executeProc()/executeFunc()', () => { describe('Application execute()/executeProc()/executeFunc()', () => {
const userWithoutPrivileges = 1; const userWithoutPrivileges = 1;
const userWithPrivileges = 9;
const userWithInheritedPrivileges = 120; const userWithInheritedPrivileges = 120;
let tx; let tx;
const {ctx} = beforeAll;
function getCtx(userId) {
return {
req: {
accessToken: {userId},
headers: {origin: 'http://localhost'}
}
};
}
beforeEach(async() => { beforeEach(async() => {
tx = await models.Application.beginTransaction({}); tx = await models.Application.beginTransaction({});
@ -42,7 +33,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => {
}); });
it('should throw error when execute procedure and not have privileges', async() => { it('should throw error when execute procedure and not have privileges', async() => {
const ctx = getCtx(userWithoutPrivileges); const ctx = {req: {accessToken: {userId: userWithoutPrivileges}}};
let error; let error;
try { try {
@ -66,7 +57,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => {
}); });
it('should execute procedure and get data', async() => { it('should execute procedure and get data', async() => {
const ctx = getCtx(userWithPrivileges);
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
@ -90,7 +80,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => {
describe('Application executeProc()', () => { describe('Application executeProc()', () => {
it('should execute procedure and get data (executeProc)', async() => { it('should execute procedure and get data (executeProc)', async() => {
const ctx = getCtx(userWithPrivileges);
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
@ -115,7 +104,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => {
describe('Application executeFunc()', () => { describe('Application executeFunc()', () => {
it('should execute function and get data', async() => { it('should execute function and get data', async() => {
const ctx = getCtx(userWithPrivileges);
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
@ -137,7 +125,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => {
}); });
it('should execute function and get data with user with inherited privileges', async() => { it('should execute function and get data with user with inherited privileges', async() => {
const ctx = getCtx(userWithInheritedPrivileges); const ctx = {req: {accessToken: {userId: userWithInheritedPrivileges}}};
try { try {
const options = {transaction: tx}; const options = {transaction: tx};

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('entry addFromPackaging()', () => { describe('entry addFromPackaging()', () => {
const supplier = 442; const supplier = 442;
@ -8,21 +8,11 @@ describe('entry addFromPackaging()', () => {
yesterday.setDate(today.getDate() - 1); yesterday.setDate(today.getDate() - 1);
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 49},
http: {
req: {
headers: {origin: 'http://localhost'},
},
},
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx,
});
}); });
it('should create an incoming travel', async() => { it('should create an incoming travel', async() => {
const ctx = {args: {isTravelReception: true, supplier}}; const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}};
const tx = await models.Entry.beginTransaction({}); const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};

View File

@ -1,24 +1,11 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('invoiceIn clone()', () => { describe('invoiceIn clone()', () => {
let ctx; const {ctx} = beforeAll;
let options; let options;
let tx; let tx;
beforeEach(async() => { beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 1},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx}; options = {transaction: tx};
tx = await models.Sale.beginTransaction({}); tx = await models.Sale.beginTransaction({});
options.transaction = tx; options.transaction = tx;
@ -28,7 +15,8 @@ describe('invoiceIn clone()', () => {
await tx.rollback(); await tx.rollback();
}); });
it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => { it('should return the cloned invoiceIn and also clone invoiceInDueDays ' +
'and invoiceInTaxes if there are any referencing the invoiceIn', async() => {
const clone = await models.InvoiceIn.clone(ctx, 1, false, options); const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
expect(clone.supplierRef).toEqual('1234(2)'); expect(clone.supplierRef).toEqual('1234(2)');
@ -51,7 +39,8 @@ describe('invoiceIn clone()', () => {
expect(invoiceInDueDay.length).toEqual(2); expect(invoiceInDueDay.length).toEqual(2);
}); });
it('should return the cloned invoiceIn and also clone invoiceInIntrastat and invoiceInTaxes if it is rectificative', async() => { it('should return the cloned invoiceIn and also clone invoiceInIntrastat ' +
'and invoiceInTaxes if it is rectificative', async() => {
const clone = await models.InvoiceIn.clone(ctx, 1, true, options); const clone = await models.InvoiceIn.clone(ctx, 1, true, options);
expect(clone.supplierRef).toEqual('1234(2)'); expect(clone.supplierRef).toEqual('1234(2)');

View File

@ -1,12 +1,9 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('itemShelving getAlternative()', () => { describe('itemShelving getAlternative()', () => {
beforeAll(async() => { beforeAll(async() => {
ctx = { mockLoopBackContext();
req: {
headers: {origin: 'http://localhost'},
}
};
}); });
it('should return a list of items without alternatives', async() => { it('should return a list of items without alternatives', async() => {

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('regularize()', () => { describe('regularize()', () => {
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { mockLoopBackContext();
accessToken: {userId: 18},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
}); });
it('should create a new ticket and add a line', async() => { it('should create a new ticket and add a line', async() => {

View File

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

View File

@ -3,7 +3,6 @@ const LoopBackContext = require('loopback-context');
describe('Supplier updateFiscalData()', () => { describe('Supplier updateFiscalData()', () => {
const supplierId = 1; const supplierId = 1;
const administrativeId = 5;
const buyerId = 35; const buyerId = 35;
const name = 'NEW PLANTS'; const name = 'NEW PLANTS';

View File

@ -1,10 +1,8 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); // const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket deleteExpeditions()', () => { describe('ticket deleteExpeditions()', () => {
beforeAll(async() => { const {ctx} = beforeAll;
mockLoopBackContext();
});
it('should delete the selected expeditions', async() => { it('should delete the selected expeditions', async() => {
const tx = await models.Expedition.beginTransaction({}); const tx = await models.Expedition.beginTransaction({});

View File

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