Merge pull request 'fixed problems in two spec files' (#954) from unit_test_fixes into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #954 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
57b75dc10e
|
@ -33,7 +33,6 @@ describe('Address updateAddress', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toBeDefined();
|
|
||||||
expect(error.message).toEqual('Incoterms is required for a non UEE member');
|
expect(error.message).toEqual('Incoterms is required for a non UEE member');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@ describe('Address updateAddress', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toBeDefined();
|
|
||||||
expect(error.message).toEqual('Customs agent is required for a non UEE member');
|
expect(error.message).toEqual('Customs agent is required for a non UEE member');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,6 +89,8 @@ describe('Address updateAddress', () => {
|
||||||
it('should return an error for a user without enough privileges', async() => {
|
it('should return an error for a user without enough privileges', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
ctx.args = {
|
ctx.args = {
|
||||||
|
@ -124,8 +124,10 @@ describe('Address updateAddress', () => {
|
||||||
expect(address.isLogifloraAllowed).toEqual(true);
|
expect(address.isLogifloraAllowed).toEqual(true);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
ctx.req.accessToken.userId = employeeId;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
ctx.req.accessToken.userId = employeeId;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -89,11 +89,12 @@ module.exports = function(Self) {
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
|
||||||
|
|
||||||
if (args.isLogifloraAllowed && !isSalesAssistant)
|
if (args.isLogifloraAllowed && !isSalesAssistant)
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('item lastEntriesFilter()', () => {
|
describe('item lastEntriesFilter()', () => {
|
||||||
const minDate = new Date(value);
|
it('should return one entry for the given item', async() => {
|
||||||
minHour.setHours(0, 0, 0, 0);
|
const minDate = new Date();
|
||||||
const maxDate = new Date(value);
|
minDate.setHours(0, 0, 0, 0);
|
||||||
maxHour.setHours(23, 59, 59, 59);
|
const maxDate = new Date();
|
||||||
|
maxDate.setHours(23, 59, 59, 59);
|
||||||
|
|
||||||
it('should return one entry for a given item', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
const tx = await models.Item.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
@ -23,13 +22,18 @@ describe('item lastEntriesFilter()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return five entries for a given item', async() => {
|
it('should return five entries for the given item', async() => {
|
||||||
|
const minDate = new Date();
|
||||||
|
minDate.setHours(0, 0, 0, 0);
|
||||||
|
minDate.setMonth(minDate.getMonth() - 2, 1);
|
||||||
|
|
||||||
|
const maxDate = new Date();
|
||||||
|
maxDate.setHours(23, 59, 59, 59);
|
||||||
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
const tx = await models.Item.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
minDate.setMonth(minDate.getMonth() - 2, 1);
|
|
||||||
|
|
||||||
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
|
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
|
||||||
const result = await models.Item.lastEntriesFilter(filter, options);
|
const result = await models.Item.lastEntriesFilter(filter, options);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue