7167-testToMaster_2414 #2244
|
@ -0,0 +1,56 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
|
describe('Ticket cloning - clone function', () => {
|
||||||
|
let ctx;
|
||||||
|
let options;
|
||||||
|
let tx;
|
||||||
|
const ticketId = 1;
|
||||||
|
const shipped = Date.vnNew();
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
},
|
||||||
|
args: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: ctx.req
|
||||||
|
});
|
||||||
|
|
||||||
|
options = {transaction: tx};
|
||||||
|
tx = await models.Ticket.beginTransaction({});
|
||||||
|
options.transaction = tx;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clone a new ticket without warehouse', async() => {
|
||||||
|
const originalTicket = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
|
const newTicketId = await models.Ticket.clone(ctx, ticketId, shipped, false, options);
|
||||||
|
const newTicket = await models.Ticket.findById(newTicketId, null, options);
|
||||||
|
|
||||||
|
expect(newTicket.clientFk).toEqual(originalTicket.clientFk);
|
||||||
|
expect(newTicket.companyFk).toEqual(originalTicket.companyFk);
|
||||||
|
expect(newTicket.addressFk).toEqual(originalTicket.addressFk);
|
||||||
|
expect(newTicket.warehouseFk).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clone a new ticket with warehouse', async() => {
|
||||||
|
const originalTicket = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
|
const newTicketId = await models.Ticket.clone(ctx, ticketId, shipped, true, options);
|
||||||
|
const newTicket = await models.Ticket.findById(newTicketId, null, options);
|
||||||
|
|
||||||
|
expect(newTicket.clientFk).toEqual(originalTicket.clientFk);
|
||||||
|
expect(newTicket.companyFk).toEqual(originalTicket.companyFk);
|
||||||
|
expect(newTicket.addressFk).toEqual(originalTicket.addressFk);
|
||||||
|
expect(newTicket.warehouseFk).toEqual(originalTicket.warehouseFk);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue