Merge pull request '2283_e2e_delete_ticket_with_stowaway' (#305) from 2283_e2e_delete_ticket_with_stowaway into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
a6b6853ec4
|
@ -10,7 +10,7 @@ export default {
|
|||
ticketsButton: '.modules-menu [ui-sref="ticket.index"]',
|
||||
invoiceOutButton: '.modules-menu [ui-sref="invoiceOut.index"]',
|
||||
claimsButton: '.modules-menu [ui-sref="claim.index"]',
|
||||
returnToModuleIndexButton: 'a[ui-sref="order.index"]',
|
||||
returnToModuleIndexButton: 'a[name="goToModuleIndex"]',
|
||||
homeButton: 'vn-topbar > div.side.start > a',
|
||||
userLocalWarehouse: '.user-popover vn-autocomplete[ng-model="$ctrl.localWarehouseFk"]',
|
||||
userLocalBank: '.user-popover vn-autocomplete[ng-model="$ctrl.localBankFk"]',
|
||||
|
@ -365,7 +365,8 @@ export default {
|
|||
firstSaleQuantity: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3)',
|
||||
firstSaleDiscount: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6)',
|
||||
invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(7) > section > span',
|
||||
setOk: 'vn-ticket-summary vn-button[label="SET OK"] > button'
|
||||
setOk: 'vn-ticket-summary vn-button[label="SET OK"] > button',
|
||||
descriptorTicketId: 'vn-ticket-descriptor > vn-descriptor-content > div > div.body > div.top > div'
|
||||
},
|
||||
ticketsIndex: {
|
||||
openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
|
||||
|
|
|
@ -4,6 +4,9 @@ import getBrowser from '../../helpers/puppeteer';
|
|||
describe('Ticket create path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
let nextMonth = new Date();
|
||||
nextMonth.setMonth(nextMonth.getMonth() + 1);
|
||||
let stowawayTicketId;
|
||||
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
|
@ -21,13 +24,9 @@ describe('Ticket create path', () => {
|
|||
});
|
||||
|
||||
it('should succeed to create a ticket', async() => {
|
||||
const nextMonth = new Date();
|
||||
nextMonth.setMonth(nextMonth.getMonth() + 1);
|
||||
|
||||
await page.autocompleteSearch(selectors.createTicketView.client, 'Tony Stark');
|
||||
await page.autocompleteSearch(selectors.createTicketView.address, 'Tony Stark');
|
||||
await page.autocompleteSearch(selectors.createTicketView.client, 'Clark Kent');
|
||||
await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth);
|
||||
await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse One');
|
||||
await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse Two');
|
||||
await page.autocompleteSearch(selectors.createTicketView.agency, 'Silla247');
|
||||
await page.waitToClick(selectors.createTicketView.createButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
@ -37,5 +36,53 @@ describe('Ticket create path', () => {
|
|||
|
||||
it('should check the url is now the summary of the ticket', async() => {
|
||||
await page.waitForState('ticket.card.summary');
|
||||
stowawayTicketId = await page.waitToGetProperty(selectors.ticketSummary.descriptorTicketId, 'innerText');
|
||||
stowawayTicketId = stowawayTicketId.substring(1);
|
||||
});
|
||||
|
||||
it('should again open the new ticket form', async() => {
|
||||
await page.waitToClick(selectors.globalItems.returnToModuleIndexButton);
|
||||
await page.waitToClick(selectors.ticketsIndex.newTicketButton);
|
||||
await page.waitForState('ticket.create');
|
||||
});
|
||||
|
||||
it('should succeed to create another ticket for the same client', async() => {
|
||||
await page.autocompleteSearch(selectors.createTicketView.client, 'Clark Kent');
|
||||
await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth);
|
||||
await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse One');
|
||||
await page.autocompleteSearch(selectors.createTicketView.agency, 'Silla247');
|
||||
await page.waitToClick(selectors.createTicketView.createButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.type).toBe('success');
|
||||
});
|
||||
|
||||
it('should check the url is now the summary of the created ticket', async() => {
|
||||
await page.waitForState('ticket.card.summary');
|
||||
});
|
||||
|
||||
it('should make the previously created ticket the stowaway of the current ticket', async() => {
|
||||
await page.waitToClick(selectors.ticketDescriptor.moreMenu);
|
||||
await page.waitToClick(selectors.ticketDescriptor.moreMenuAddStowaway);
|
||||
await page.waitToClick(selectors.ticketDescriptor.addStowawayDialogFirstTicket);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.type).toBe('success');
|
||||
});
|
||||
|
||||
it('should delete the current ticket', async() => {
|
||||
await page.waitToClick(selectors.ticketDescriptor.moreMenu);
|
||||
await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket);
|
||||
await page.waitToClick(selectors.ticketDescriptor.acceptDeleteButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.type).toBe('success');
|
||||
});
|
||||
|
||||
it('should search for the stowaway ticket of the previously deleted ticket', async() => {
|
||||
await page.accessToSearchResult(stowawayTicketId);
|
||||
const result = await page.countElement(selectors.ticketDescriptor.shipButton);
|
||||
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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(`
|
||||
INSERT INTO vn.stowaway(id, shipFk)
|
||||
VALUES (?, ?)`, [stowawayTicketId, ticketId]);
|
||||
let sampleTicket = await models.Ticket.findById(12);
|
||||
let sampleStowaway = await models.Ticket.findById(13);
|
||||
|
||||
deletedClaim = await app.models.Claim.findById(claimIdToRemove);
|
||||
await app.models.Claim.destroyById(claimIdToRemove);
|
||||
await app.models.Ticket.setDeleted(ctx, ticketId);
|
||||
sampleTicket.id = undefined;
|
||||
let shipTicket = await models.Ticket.create(sampleTicket);
|
||||
|
||||
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: {
|
||||
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