feat: refs #6276 test expeditionPallet_get
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
90b1e8d664
commit
e69ec2c856
|
@ -204,5 +204,6 @@
|
|||
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified",
|
||||
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}",
|
||||
"Incorrect pin": "Incorrect pin.",
|
||||
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified"
|
||||
"This machine is already in use.": "This machine is already in use.",
|
||||
"This pallet does not exist": "This pallet does not exist"
|
||||
}
|
|
@ -340,6 +340,6 @@
|
|||
"No tickets to invoice": "No hay tickets para facturar",
|
||||
"No hay tickets para sacar": "No hay tickets para sacar",
|
||||
"There is no zone for these parameters 999999": "There is no zone for these parameters 999999",
|
||||
"Esta máquina ya está en uso.": "Esta máquina ya está en uso.",
|
||||
"This machine is already in use.": "This machine is already in use."
|
||||
"This machine is already in use.": "Esta máquina ya está en uso.",
|
||||
"This pallet does not exist": "Este palet no existe"
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getPallet', {
|
||||
Self.remoteMethodCtx('getPallet', {
|
||||
description: 'Get pallet',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
|
@ -20,7 +20,13 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.getPallet = async expeditionFk => {
|
||||
Self.getPallet = async(ctx, expeditionFk, options) => {
|
||||
const myOptions = {};
|
||||
const $t = ctx.req.__;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
try {
|
||||
const pallet = await Self.findOne({
|
||||
fields: ['truckFk'],
|
||||
|
@ -35,7 +41,7 @@ module.exports = Self => {
|
|||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
if (pallet) {
|
||||
const truck = pallet.expeditionTruck();
|
||||
|
@ -46,7 +52,7 @@ module.exports = Self => {
|
|||
};
|
||||
}
|
||||
|
||||
throw new UserError('palletDoesNotExist');
|
||||
throw new UserError($t('This pallet does not exist'));
|
||||
} catch (e) {
|
||||
return {message: e.message};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('expeditonPallet getPallet()', () => {
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
accessToken: {userId: 9},
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should obtain the pallet data', async() => {
|
||||
const pallet = await models.ExpeditionPallet.getPallet(ctx, 1);
|
||||
|
||||
expect(pallet).toBeDefined();
|
||||
expect(pallet.truckFk).toEqual(1);
|
||||
expect(pallet.description).toEqual('BEST TRUCK IN FLEET');
|
||||
});
|
||||
|
||||
it('should throw an error when the pallet does not exist', async() => {
|
||||
try {
|
||||
await models.ExpeditionPallet.getPallet(ctx, 1);
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('This pallet does not exist');
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue