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)
|
if (hasItemShelvingSales && !isSalesAssistant)
|
||||||
throw new UserError(`You cannot delete a ticket that part of it is being prepared`);
|
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
|
// Check for existing claim
|
||||||
const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}});
|
const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}});
|
||||||
if (claimOfATicket)
|
if (claimOfATicket)
|
||||||
|
@ -69,10 +57,23 @@ module.exports = Self => {
|
||||||
if (hasPurchaseRequests)
|
if (hasPurchaseRequests)
|
||||||
throw new UserError('You must delete all the buy requests first');
|
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
|
// Remove ticket greuges
|
||||||
const ticketGreuges = await models.Greuge.find({where: {ticketFk: id}});
|
const ticketGreuges = await models.Greuge.find({where: {ticketFk: id}});
|
||||||
const ownGreuges = ticketGreuges.every(greuge => {
|
const ownGreuges = ticketGreuges.every(greuge => {
|
||||||
return greuge.ticketFk = id;
|
return greuge.ticketFk == id;
|
||||||
});
|
});
|
||||||
if (ownGreuges) {
|
if (ownGreuges) {
|
||||||
for (const greuge of ticketGreuges) {
|
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;
|
let otherTicketId;
|
||||||
if (ticket.stowaway())
|
if (ticket.stowaway())
|
||||||
otherTicketId = ticket.stowaway().shipFk;
|
otherTicketId = ticket.stowaway().shipFk;
|
||||||
|
@ -112,6 +113,7 @@ module.exports = Self => {
|
||||||
otherTicketId = ticket.ship().id;
|
otherTicketId = ticket.ship().id;
|
||||||
|
|
||||||
if (otherTicketId) {
|
if (otherTicketId) {
|
||||||
|
await models.Ticket.deleteStowaway(ctx, otherTicketId);
|
||||||
await models.TicketTracking.changeState(ctx, {
|
await models.TicketTracking.changeState(ctx, {
|
||||||
ticketFk: otherTicketId,
|
ticketFk: otherTicketId,
|
||||||
code: 'FIXING'
|
code: 'FIXING'
|
||||||
|
|
|
@ -1,116 +1,7 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const models = app.models;
|
const models = app.models;
|
||||||
|
|
||||||
// 2301 Failing tests
|
describe('ticket setDeleted()', () => {
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if the given ticket has a claim', async() => {
|
it('should throw an error if the given ticket has a claim', async() => {
|
||||||
const ticketId = 16;
|
const ticketId = 16;
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
@ -134,13 +25,11 @@ xdescribe('ticket deleted()', () => {
|
||||||
expect(error.message).toEqual('You must delete the claim id %d first');
|
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() => {
|
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 ticketId = 16;
|
const employeeUser = 110;
|
||||||
const claimIdToRemove = 2;
|
|
||||||
const stowawayTicketId = 17;
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
req: {
|
req: {
|
||||||
accessToken: {userId: 106},
|
accessToken: {userId: employeeUser},
|
||||||
headers: {
|
headers: {
|
||||||
origin: 'http://localhost:5000'
|
origin: 'http://localhost:5000'
|
||||||
},
|
},
|
||||||
|
@ -148,20 +37,66 @@ xdescribe('ticket deleted()', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await app.models.Stowaway.rawSql(`
|
let sampleTicket = await models.Ticket.findById(12);
|
||||||
INSERT INTO vn.stowaway(id, shipFk)
|
let sampleStowaway = await models.Ticket.findById(13);
|
||||||
VALUES (?, ?)`, [stowawayTicketId, ticketId]);
|
|
||||||
|
|
||||||
deletedClaim = await app.models.Claim.findById(claimIdToRemove);
|
sampleTicket.id = undefined;
|
||||||
await app.models.Claim.destroyById(claimIdToRemove);
|
let shipTicket = await models.Ticket.create(sampleTicket);
|
||||||
await app.models.Ticket.setDeleted(ctx, ticketId);
|
|
||||||
|
|
||||||
const stowawayTicket = await app.models.TicketState.findOne({
|
sampleStowaway.id = undefined;
|
||||||
|
let stowawayTicket = await models.Ticket.create(sampleStowaway);
|
||||||
|
|
||||||
|
await models.Stowaway.rawSql(`
|
||||||
|
INSERT INTO vn.stowaway(id, shipFk)
|
||||||
|
VALUES (?, ?)`, [stowawayTicket.id, shipTicket.id]);
|
||||||
|
|
||||||
|
const boardingState = await models.State.findOne({
|
||||||
where: {
|
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