Updated unit tests
gitea/salix/2150-travel_filter_by_ref This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-02-27 12:39:58 +01:00
parent 70210e87c9
commit ccd28114ca
2 changed files with 27 additions and 10 deletions

View File

@ -84,7 +84,9 @@ module.exports = Self => {
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return {'t.id': value};
return /^\d+$/.test(value)
? {'t.id': value}
: {'t.ref': {like: `%${value}%`}};
case 'ref':
return {'t.ref': {like: `%${value}%`}};
case 'shippedFrom':

View File

@ -2,38 +2,53 @@ const app = require('vn-loopback/server/server');
describe('Travel filter()', () => {
it('should return the travel matching "search"', async() => {
let ctx = {
const ctx = {
args: {
search: 1
}
};
let result = await app.models.Travel.filter(ctx);
const result = await app.models.Travel.filter(ctx);
const firstRow = result[0];
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1);
expect(firstRow.id).toEqual(1);
});
it('should return the travel matching "search" by ref', async() => {
const ctx = {
args: {
search: 'third'
}
};
const result = await app.models.Travel.filter(ctx);
const firstRow = result[0];
expect(result.length).toEqual(1);
expect(firstRow.id).toEqual(3);
});
it('should return the travel matching "warehouse out"', async() => {
let ctx = {
const ctx = {
args: {
warehouseOutFk: 2
}
};
let result = await app.models.Travel.filter(ctx);
const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(8);
});
it('should return the travel matching "total entries"', async() => {
let ctx = {
const ctx = {
args: {
totalEntries: 1,
}
};
let result = await app.models.Travel.filter(ctx);
const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(5);
});
@ -44,14 +59,14 @@ describe('Travel filter()', () => {
from.setHours(0, 0, 0, 0);
to.setHours(23, 59, 59, 999);
to.setDate(to.getDate() + 1);
let ctx = {
const ctx = {
args: {
shippedFrom: from,
shippedTo: to
}
};
let result = await app.models.Travel.filter(ctx);
const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(1);
});