2314 server side unit test fixed
This commit is contained in:
parent
4b262dc3cc
commit
4b1e79a433
|
@ -43,18 +43,6 @@ module.exports = Self => {
|
|||
if (hasItemShelvingSales && !isSalesAssistant)
|
||||
throw new UserError(`You cannot delete a ticket that part of it is being prepared`);
|
||||
|
||||
if (hasItemShelvingSales && isSalesAssistant) {
|
||||
const promises = [];
|
||||
for (let sale of sales) {
|
||||
if (sale.itemShelvingSale()) {
|
||||
const itemShelvingSale = sale.itemShelvingSale();
|
||||
const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id);
|
||||
promises.push(destroyedShelving);
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
// Check for existing claim
|
||||
const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}});
|
||||
if (claimOfATicket)
|
||||
|
@ -69,10 +57,23 @@ module.exports = Self => {
|
|||
if (hasPurchaseRequests)
|
||||
throw new UserError('You must delete all the buy requests first');
|
||||
|
||||
// removes item shelvings
|
||||
if (hasItemShelvingSales && isSalesAssistant) {
|
||||
const promises = [];
|
||||
for (let sale of sales) {
|
||||
if (sale.itemShelvingSale()) {
|
||||
const itemShelvingSale = sale.itemShelvingSale();
|
||||
const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id);
|
||||
promises.push(destroyedShelving);
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
// Remove ticket greuges
|
||||
const ticketGreuges = await models.Greuge.find({where: {ticketFk: id}});
|
||||
const ownGreuges = ticketGreuges.every(greuge => {
|
||||
return greuge.ticketFk = id;
|
||||
return greuge.ticketFk == id;
|
||||
});
|
||||
if (ownGreuges) {
|
||||
for (const greuge of ticketGreuges) {
|
||||
|
@ -104,7 +105,7 @@ module.exports = Self => {
|
|||
}]
|
||||
});
|
||||
|
||||
// Change state to "fixing" if contains an stowaway
|
||||
// Change state to "fixing" if contains an stowaway and removed the link between them
|
||||
let otherTicketId;
|
||||
if (ticket.stowaway())
|
||||
otherTicketId = ticket.stowaway().shipFk;
|
||||
|
@ -112,6 +113,7 @@ module.exports = Self => {
|
|||
otherTicketId = ticket.ship().id;
|
||||
|
||||
if (otherTicketId) {
|
||||
await models.Ticket.deleteStowaway(ctx, otherTicketId);
|
||||
await models.TicketTracking.changeState(ctx, {
|
||||
ticketFk: otherTicketId,
|
||||
code: 'FIXING'
|
||||
|
|
|
@ -1,116 +1,7 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = app.models;
|
||||
|
||||
// 2301 Failing tests
|
||||
xdescribe('ticket deleted()', () => {
|
||||
let ticket;
|
||||
let sale;
|
||||
let deletedClaim;
|
||||
|
||||
beforeAll(async done => {
|
||||
let originalTicket = await models.Ticket.findOne({where: {id: 16}});
|
||||
originalTicket.id = null;
|
||||
ticket = await models.Ticket.create(originalTicket);
|
||||
sale = await models.Sale.create({
|
||||
ticketFk: ticket.id,
|
||||
itemFk: 4,
|
||||
concept: 'Melee weapon',
|
||||
quantity: 10
|
||||
});
|
||||
|
||||
await models.ItemShelvingSale.create({
|
||||
itemShelvingFk: 1,
|
||||
saleFk: sale.id,
|
||||
quantity: 10,
|
||||
userFk: 106
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(async done => {
|
||||
const ticketId = 16;
|
||||
const stowawayTicketId = 17;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 106},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
await models.Ticket.destroyById(ticket.id);
|
||||
const stowaway = await models.Stowaway.findOne({
|
||||
where: {
|
||||
id: stowawayTicketId,
|
||||
shipFk: ticketId
|
||||
}
|
||||
});
|
||||
await stowaway.destroy();
|
||||
await models.Claim.create(deletedClaim);
|
||||
await models.TicketTracking.changeState(ctx, {
|
||||
ticketFk: ticketId,
|
||||
code: 'OK'
|
||||
});
|
||||
await models.TicketTracking.changeState(ctx, {
|
||||
ticketFk: stowawayTicketId,
|
||||
code: 'OK'
|
||||
});
|
||||
const orgTicket = await models.Ticket.findById(ticketId);
|
||||
await orgTicket.updateAttribute('isDeleted', false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should make sure the ticket is not deleted yet', async() => {
|
||||
expect(ticket.isDeleted).toEqual(false);
|
||||
});
|
||||
|
||||
it('should make sure the ticket sale has an item shelving', async() => {
|
||||
const sales = await models.Sale.find({
|
||||
include: {relation: 'itemShelvingSale'},
|
||||
where: {ticketFk: ticket.id}
|
||||
});
|
||||
const hasItemShelvingSales = sales.some(sale => {
|
||||
return sale.itemShelvingSale();
|
||||
});
|
||||
|
||||
expect(hasItemShelvingSales).toEqual(true);
|
||||
});
|
||||
|
||||
it('should set a ticket to deleted and remove all item shelvings', async() => {
|
||||
const salesAssistantId = 21;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: salesAssistantId},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
await app.models.Ticket.setDeleted(ctx, ticket.id);
|
||||
|
||||
let deletedTicket = await app.models.Ticket.findOne({
|
||||
where: {id: ticket.id},
|
||||
fields: ['isDeleted']
|
||||
});
|
||||
|
||||
expect(deletedTicket.isDeleted).toEqual(true);
|
||||
});
|
||||
|
||||
it('should not have any item shelving', async() => {
|
||||
const sales = await models.Sale.find({
|
||||
include: {relation: 'itemShelvingSale'},
|
||||
where: {ticketFk: ticket.id}
|
||||
});
|
||||
const hasItemShelvingSales = sales.some(sale => {
|
||||
return sale.itemShelvingSale();
|
||||
});
|
||||
|
||||
expect(hasItemShelvingSales).toEqual(false);
|
||||
});
|
||||
|
||||
describe('ticket setDeleted()', () => {
|
||||
it('should throw an error if the given ticket has a claim', async() => {
|
||||
const ticketId = 16;
|
||||
const ctx = {
|
||||
|
@ -134,13 +25,11 @@ xdescribe('ticket deleted()', () => {
|
|||
expect(error.message).toEqual('You must delete the claim id %d first');
|
||||
});
|
||||
|
||||
it('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => {
|
||||
const ticketId = 16;
|
||||
const claimIdToRemove = 2;
|
||||
const stowawayTicketId = 17;
|
||||
it('should delete the ticket, remove the stowaway link and change the stowaway ticket state to "FIXING" and get ride of the itemshelving', async() => {
|
||||
const employeeUser = 110;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 106},
|
||||
accessToken: {userId: employeeUser},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
|
@ -148,20 +37,66 @@ xdescribe('ticket deleted()', () => {
|
|||
}
|
||||
};
|
||||
|
||||
await app.models.Stowaway.rawSql(`
|
||||
let sampleTicket = await models.Ticket.findById(12);
|
||||
let sampleStowaway = await models.Ticket.findById(13);
|
||||
|
||||
sampleTicket.id = undefined;
|
||||
let shipTicket = await models.Ticket.create(sampleTicket);
|
||||
|
||||
sampleStowaway.id = undefined;
|
||||
let stowawayTicket = await models.Ticket.create(sampleStowaway);
|
||||
|
||||
await models.Stowaway.rawSql(`
|
||||
INSERT INTO vn.stowaway(id, shipFk)
|
||||
VALUES (?, ?)`, [stowawayTicketId, ticketId]);
|
||||
VALUES (?, ?)`, [stowawayTicket.id, shipTicket.id]);
|
||||
|
||||
deletedClaim = await app.models.Claim.findById(claimIdToRemove);
|
||||
await app.models.Claim.destroyById(claimIdToRemove);
|
||||
await app.models.Ticket.setDeleted(ctx, ticketId);
|
||||
|
||||
const stowawayTicket = await app.models.TicketState.findOne({
|
||||
const boardingState = await models.State.findOne({
|
||||
where: {
|
||||
ticketFk: stowawayTicketId
|
||||
code: 'BOARDING'
|
||||
}
|
||||
});
|
||||
await models.TicketTracking.create({
|
||||
ticketFk: stowawayTicket.id,
|
||||
stateFk: boardingState.id,
|
||||
workerFk: ctx.req.accessToken.userId
|
||||
});
|
||||
|
||||
const okState = await models.State.findOne({
|
||||
where: {
|
||||
code: 'OK'
|
||||
}
|
||||
});
|
||||
await models.TicketTracking.create({
|
||||
ticketFk: shipTicket.id,
|
||||
stateFk: okState.id,
|
||||
workerFk: ctx.req.accessToken.userId
|
||||
});
|
||||
|
||||
let stowawayTicketState = await models.TicketState.findOne({
|
||||
where: {
|
||||
ticketFk: stowawayTicket.id
|
||||
}
|
||||
});
|
||||
|
||||
expect(stowawayTicket.code).toEqual('FIXING');
|
||||
let stowaway = await models.Stowaway.findById(shipTicket.id);
|
||||
|
||||
expect(stowaway).toBeDefined();
|
||||
expect(stowawayTicketState.code).toEqual('BOARDING');
|
||||
|
||||
await models.Ticket.setDeleted(ctx, shipTicket.id);
|
||||
|
||||
stowawayTicketState = await models.TicketState.findOne({
|
||||
where: {
|
||||
ticketFk: stowawayTicket.id
|
||||
}
|
||||
});
|
||||
|
||||
stowaway = await models.Stowaway.findById(shipTicket.id);
|
||||
|
||||
expect(stowaway).toBeNull();
|
||||
expect(stowawayTicketState.code).toEqual('FIXING');
|
||||
|
||||
await shipTicket.destroy();
|
||||
await stowawayTicket.destroy();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue