7253-devToTest_2418 #2350
|
@ -24,31 +24,19 @@ module.exports = Self => {
|
||||||
Self.addDropOff = async(ticketFk, note, options) => {
|
Self.addDropOff = async(ticketFk, note, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
const observationTypeDropOff = await models.ObservationType.findOne({
|
||||||
tx = await Self.beginTransaction({});
|
where: {code: 'dropOff'}
|
||||||
myOptions.transaction = tx;
|
}, myOptions);
|
||||||
}
|
|
||||||
try {
|
|
||||||
const observationTypeDropOff = await models.ObservationType.findOne({
|
|
||||||
where: {code: 'dropOff'}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
await models.TicketObservation.create({
|
await models.TicketObservation.create({
|
||||||
ticketFk: ticketFk,
|
ticketFk: ticketFk,
|
||||||
observationTypeFk: observationTypeDropOff.id,
|
observationTypeFk: observationTypeDropOff.id,
|
||||||
description: note
|
description: note
|
||||||
|
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
} catch (error) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,25 +6,19 @@ describe('ticketObservation addDropOff()', () => {
|
||||||
const code = 'dropOff';
|
const code = 'dropOff';
|
||||||
|
|
||||||
it('should return a dropOff note', async() => {
|
it('should return a dropOff note', async() => {
|
||||||
const myOptions = {};
|
const tx = await models.TicketObservation.beginTransaction({});
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await models.TicketObservation.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
await models.TicketObservation.addDropOff(
|
await models.TicketObservation.addDropOff(
|
||||||
ticketFk, note, myOptions);
|
ticketFk, note, options);
|
||||||
|
|
||||||
const observationTypeDropOff = await models.TicketObservation.find({
|
const observationTypeDropOff = await models.TicketObservation.find({
|
||||||
where: {
|
where: {
|
||||||
ticketFk,
|
ticketFk,
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, options);
|
||||||
|
|
||||||
expect(observationTypeDropOff.length).toEqual(1);
|
expect(observationTypeDropOff.length).toEqual(1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue