feat: add backTest

This commit is contained in:
Vicent Llopis 2022-11-25 11:50:54 +01:00
parent bd91d4a649
commit bca79e1240
2 changed files with 12 additions and 40 deletions

View File

@ -1,46 +1,11 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('ticket setDelivered()', () => {
const userId = 50;
const activeCtx = {
accessToken: {userId: userId},
};
describe('ticketLog getChanges()', () => {
it('should return the changes in the sales of a ticket', async() => {
const ticketId = 1;
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
const changues = await models.TicketLog.getChanges({id: ticketId});
it('should return the state which has been applied to the given tickets', async() => {
const tx = await models.TicketTracking.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 49}}};
const originalTicketOne = await models.Ticket.findById(8, null, options);
const originalTicketTwo = await models.Ticket.findById(10, null, options);
originalTicketOne.id = null;
originalTicketTwo.id = null;
const ticketOne = await models.Ticket.create(originalTicketOne, options);
const ticketTwo = await models.Ticket.create(originalTicketTwo, options);
const delivered = await models.State.findOne({where: {code: 'delivered'}, fields: ['id']}, options);
const params = [ticketOne.id, ticketTwo.id];
const state = await models.TicketTracking.setDelivered(ctx, params, options);
expect(state.id).toEqual(delivered.id);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(changues).toContain(`cambia de 1 a 10`);
});
});

View File

@ -15,9 +15,16 @@ describe('ticket sendSms()', () => {
const sms = await models.Ticket.sendSms(ctx, id, destination, message, options);
const createdLog = await models.TicketLog.findById(sms.logId, null, options);
const filter = {
ticketFk: createdLog.originFk
};
const ticketSms = await models.TicketSms.findOne(filter, options);
const json = JSON.parse(JSON.stringify(createdLog.newInstance));
expect(json.message).toEqual(message);
expect(ticketSms.ticketFk).toEqual(createdLog.originFk);
await tx.rollback();
} catch (e) {