#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
7 changed files with 26 additions and 16 deletions
Showing only changes of commit 21cf05ddd0 - Show all commits

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);