fix: refs #6276 fix tests & errors
gitea/salix/pipeline/pr-dev Build queued... Details

This commit is contained in:
Jorge Penadés 2024-02-02 09:23:29 +01:00
parent 9f9d953b86
commit 21cf05ddd0
7 changed files with 26 additions and 16 deletions

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
fdescribe('itemShelving return()', () => { describe('itemShelving return()', () => {
beforeAll(async() => { beforeAll(async() => {
ctx = { ctx = {
req: { req: {

View File

@ -24,12 +24,17 @@ module.exports = Self => {
}, },
}); });
Self.card = async(itemFk, warehouseFk) => { Self.card = async(itemFk, warehouseFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const models = Self.app.models; const models = Self.app.models;
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]); const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk], myOptions);
const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk]); const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk], myOptions);
const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem); const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem);
const barcodes = await models.ItemBarcode.find({ const barcodes = await models.ItemBarcode.find({

View File

@ -3,7 +3,7 @@
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');
fdescribe('sale model ', () => { describe('sale model ', () => {
const ctx = { const ctx = {
req: { req: {
accessToken: {userId: 9}, accessToken: {userId: 9},

View File

@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => {
const result = await app.models.Travel.extraCommunityFilter(ctx, filter); const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
expect(result.length).toEqual(9); expect(result.length).toEqual(8);
}); });
it('should return the travel matching "cargoSupplierFk"', async() => { it('should return the travel matching "cargoSupplierFk"', async() => {

View File

@ -80,6 +80,6 @@ describe('Travel filter()', () => {
const result = await app.models.Travel.filter(ctx); const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(6); expect(result.length).toEqual(5);
}); });
}); });

View File

@ -15,7 +15,7 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const isOperator = await Self.findById(user, myOptions); const isOperator = await Self.findById(userId, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions); if (!isOperator) await Self.create({workerFk: userId}, myOptions);
}; };
}; };

View File

@ -1,8 +1,8 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
describe('operator add()', () => { describe('operator add()', () => {
const itBoss = 104; const noOperator = 104;
const noWorker = 100000; const operator = 9;
beforeAll(async() => { beforeAll(async() => {
ctx = { ctx = {
@ -14,18 +14,23 @@ describe('operator add()', () => {
}; };
}); });
it('should throw an error if the worker does not exist', async() => { it('should not add an existent operator', async() => {
const tx = await models.Operator.beginTransaction({}); const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
ctx.req.accessToken.userId = noWorker; ctx.req.accessToken.userId = operator;
try { try {
const operatorBefore = await models.Operator.find(null, options);
const isOperator = await models.Operator.findOne(null, options);
expect(isOperator).toBeDefined();
await models.Operator.add(ctx, options); await models.Operator.add(ctx, options);
const operatorAfter = await models.Operator.find(null, options);
expect(operatorBefore.length).toEqual(operatorAfter.length);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
const error = e;
expect(error.message).toEqual('This worker does not exist');
await tx.rollback(); await tx.rollback();
} }
}); });
@ -33,7 +38,7 @@ describe('operator add()', () => {
it('should add a new operator successfully', async() => { it('should add a new operator successfully', async() => {
const tx = await models.Operator.beginTransaction({}); const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
ctx.req.accessToken.userId = itBoss; ctx.req.accessToken.userId = noOperator;
try { try {
const operatorBefore = await models.Operator.find(null, options); const operatorBefore = await models.Operator.find(null, options);