#1398 Test unitarios de filtros
gitea/salix/dev This commit has test failures Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-05-13 14:34:37 +02:00
parent eae6a6f43c
commit 18d0aa9282
10 changed files with 340 additions and 5 deletions

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethod('getLanded', {
description: 'Returns the first shipped and landed possible for params',
description: 'Returns the landed',
accessType: 'READ',
accepts: [{
arg: 'params',

View File

@ -0,0 +1,34 @@
const app = require('vn-loopback/server/server');
describe('Agency getAgenciesWithWarehouse()', () => {
const today = new Date();
it('should return the agencies that can handle the given delivery request', async() => {
let filter = {
addressFk: 101,
landed: today,
warehouseFk: 1
};
let result = await app.models.Agency.getAgenciesWithWarehouse(filter);
let agencies = result[0];
expect(agencies.length).toEqual(4);
expect(agencies[0].agency).toEqual('inhouse pickup');
expect(agencies[1].agency).toEqual('Super-Man delivery');
expect(agencies[2].agency).toEqual('Silla247');
expect(agencies[3].agency).toEqual('Silla247Expensive');
});
it('should return no agencies if the date is incorrect', async() => {
let filter = {
addressFk: 101,
landed: null,
warehouseFk: 1
};
let result = await app.models.Agency.getAgenciesWithWarehouse(filter);
let agencies = result[0];
expect(agencies.length).toEqual(0);
});
});

View File

@ -0,0 +1,16 @@
const app = require('vn-loopback/server/server');
describe('Agency getFirstShipped()', () => {
it('should return the first shipped and landed possible for the filter', async() => {
let filter = {
agencyModeFk: 1,
addressFk: 101,
warehouseFk: 1
};
let result = await app.models.Agency.getFirstShipped(filter);
expect(result.vShipped).toBeDefined();
expect(result.vLanded).toBeDefined();
});
});

View File

@ -0,0 +1,17 @@
const app = require('vn-loopback/server/server');
describe('Agency getLanded()', () => {
const today = new Date();
it('should return the landed', async() => {
let filter = {
shipped: today,
addressFk: 101,
agencyModeFk: 1,
warehouseFk: 1
};
let result = await app.models.Agency.getLanded(filter);
expect(result).toEqual(jasmine.any(Date));
});
});

View File

@ -0,0 +1,16 @@
const app = require('vn-loopback/server/server');
describe('Agency getShipped()', () => {
const today = new Date();
it('should return the first shipped possible for params', async() => {
let filter = {
landed: today,
addressFk: 101,
agencyModeFk: 1,
};
let result = await app.models.Agency.getShipped(filter);
expect(result).toEqual(jasmine.any(Date));
});
});

View File

@ -0,0 +1,20 @@
const app = require('vn-loopback/server/server');
describe('Agency landsThatDay()', () => {
const today = new Date();
it('should return a list of agencies that can land a shipment on a day for an address', async() => {
let filter = {
addressFk: 101,
landed: today,
};
let result = await app.models.Agency.landsThatDay(filter);
let agencies = result[0];
expect(agencies.length).toEqual(4);
expect(agencies[0].agency).toEqual('inhouse pickup');
expect(agencies[1].agency).toEqual('Super-Man delivery');
expect(agencies[2].agency).toEqual('Silla247');
expect(agencies[3].agency).toEqual('Silla247Expensive');
});
});

View File

@ -71,7 +71,7 @@ module.exports = Self => {
}
});
Self.filter = async(ctx, filter) => {
Self.filter = async ctx => {
let conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => {
@ -95,7 +95,7 @@ module.exports = Self => {
}
});
filter = mergeFilters(ctx.args.filter, {where});
let filter = mergeFilters(ctx.args.filter, {where});
let stmts = [];
let stmt;

View File

@ -0,0 +1,111 @@
const app = require('vn-loopback/server/server');
describe('InvoiceOut filter()', () => {
let today = new Date();
today.setHours(2, 0, 0, 0);
it('should return the invoice out matching ref', async() => {
let ctx = {
args: {
search: 'T4444444',
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].ref).toEqual('T4444444');
});
it('should return the invoice out matching clientFk', async() => {
let ctx = {
args: {
clientFk: 102,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].ref).toEqual('T2222222');
});
it('should return the invoice out matching hasPdf', async() => {
let ctx = {
args: {
hasPdf: true,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(5);
});
it('should return the invoice out matching amount', async() => {
let ctx = {
args: {
amount: 208.35,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].ref).toEqual('T2222222');
});
it('should return the invoice out matching min and max', async() => {
let ctx = {
args: {
min: 20.10,
max: 200,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(2);
});
it('should return the invoice out matching issued', async() => {
let ctx = {
args: {
issued: today,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the invoice out matching created', async() => {
let ctx = {
args: {
created: today,
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(5);
});
it('should return the invoice out matching dued', async() => {
let ctx = {
args: {
dued: today
}
};
let result = await app.models.InvoiceOut.filter(ctx);
expect(result.length).toEqual(1);
});
});

View File

@ -65,7 +65,7 @@ module.exports = Self => {
}
});
Self.filter = async(ctx, filter) => {
Self.filter = async ctx => {
let conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => {
@ -89,7 +89,7 @@ module.exports = Self => {
}
});
filter = mergeFilters(ctx.args.filter, {where});
let filter = mergeFilters(ctx.args.filter, {where});
let stmts = [];
let stmt;

View File

@ -0,0 +1,121 @@
const app = require('vn-loopback/server/server');
describe('Route filter()', () => {
let today = new Date();
today.setHours(2, 0, 0, 0);
it('should return the routes matching "search"', async() => {
let ctx = {
args: {
search: 1,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1);
});
it('should return the routes matching "from"', async() => {
let ctx = {
args: {
from: today,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(7);
});
it('should return the routes matching "to"', async() => {
let ctx = {
args: {
to: today,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(7);
});
it('should return the routes matching "m3"', async() => {
let ctx = {
args: {
m3: 4.2,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "description"', async() => {
let ctx = {
args: {
description: 'third route',
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "workerFk"', async() => {
let ctx = {
args: {
workerFk: 56,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(5);
});
it('should return the routes matching "warehouseFk"', async() => {
let ctx = {
args: {
warehouseFk: 1,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(7);
ctx.args.warehouseFk = 2;
result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(0);
});
it('should return the routes matching "vehicleFk"', async() => {
let ctx = {
args: {
vehicleFk: 2,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "agencyModeFk"', async() => {
let ctx = {
args: {
agencyModeFk: 1,
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(2);
});
});