#549 threeLastActive.js Backend unit tests
This commit is contained in:
parent
35a8a7d7dc
commit
25b5cfe99f
|
@ -1,10 +1,9 @@
|
||||||
const app = require(`${servicesDir}/ticket/server/server`);
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||||||
|
|
||||||
describe('ticket getTaxes()', () => {
|
describe('ticket getTaxes()', () => {
|
||||||
it('should call the getTaxes method', async() => {
|
it('should return the tax of a given ticket', async() => {
|
||||||
await app.models.Ticket.getTaxes(1)
|
let result = await app.models.Ticket.getTaxes(1);
|
||||||
.then(response => {
|
|
||||||
expect(response[0].tax).toEqual(20.95);
|
expect(result[0].tax).toEqual(20.95);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
const app = require(`${servicesDir}/ticket/server/server`);
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||||||
|
|
||||||
describe('ticket getTotal()', () => {
|
describe('ticket getTotal()', () => {
|
||||||
it('should call the getTotal method and return the response', async() => {
|
it('should return the total of a ticket', async() => {
|
||||||
await app.models.Ticket.getTotal(1)
|
let result = await app.models.Ticket.getTotal(1);
|
||||||
.then(response => {
|
|
||||||
expect(response).toEqual(448.25);
|
expect(result).toEqual(448.25);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should call the getTotal method and return zero if doesn't have lines`, async() => {
|
it(`should return zero if the ticket doesn't have lines`, async() => {
|
||||||
await app.models.Ticket.getTotal(13)
|
let result = await app.models.Ticket.getTotal(13);
|
||||||
.then(response => {
|
|
||||||
expect(response).toEqual(0);
|
expect(result).toEqual(0);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||||||
|
|
||||||
|
describe('ticket threeLastActive()', () => {
|
||||||
|
it('should return the last three active tickets', async() => {
|
||||||
|
let expectedResult = [
|
||||||
|
{id: 12, shipped: '2018-09-14 00:00:00', agencyName: 'inhouse pickup', warehouseName: 'Warehouse One'},
|
||||||
|
{id: 13, shipped: '2018-10-14 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'},
|
||||||
|
{id: 14, shipped: '2018-11-14 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'}
|
||||||
|
];
|
||||||
|
expectedResult = JSON.stringify(expectedResult);
|
||||||
|
|
||||||
|
let params = {clientFk: 101, ticketFk: 1};
|
||||||
|
let result = await app.models.Ticket.threeLastActive(params);
|
||||||
|
result = JSON.stringify(result);
|
||||||
|
|
||||||
|
expect(result).toEqual(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
|
@ -18,7 +18,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.threeLastActive = async filter => {
|
Self.threeLastActive = async params => {
|
||||||
let query = `
|
let query = `
|
||||||
SELECT t.id,t.shipped,a.name AS agencyName,w.name AS warehouseName
|
SELECT t.id,t.shipped,a.name AS agencyName,w.name AS warehouseName
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
|
@ -28,7 +28,7 @@ module.exports = Self => {
|
||||||
WHERE t.shipped > CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ?
|
WHERE t.shipped > CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ?
|
||||||
ORDER BY t.shipped
|
ORDER BY t.shipped
|
||||||
LIMIT 3`;
|
LIMIT 3`;
|
||||||
let result = await Self.rawSql(query, [filter.clientFk, filter.ticketFk]);
|
let tickets = await Self.rawSql(query, [params.clientFk, params.ticketFk]);
|
||||||
return result;
|
return tickets;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue