small refactors for #2512

This commit is contained in:
Carlos Jimenez Ruiz 2020-10-30 10:45:55 +01:00
parent 25684ec521
commit 2f6b3f0c38
3 changed files with 6 additions and 40 deletions

View File

@ -42,21 +42,21 @@ describe('Ticket purchase request path', () => {
expect(message.type).toBe('success'); expect(message.type).toBe('success');
}); });
it('should confirm the new request was added', async() => { it('should check the new request was added', async() => {
await page.reloadSection('ticket.card.request.index'); await page.reloadSection('ticket.card.request.index');
const result = await page.waitToGetProperty(selectors.ticketRequests.thirdRequestQuantity, 'value'); const result = await page.waitToGetProperty(selectors.ticketRequests.thirdRequestQuantity, 'value');
expect(result).toEqual('99'); expect(result).toEqual('99');
}); });
it(`should confirm first request can't be edited as its state is different to new`, async() => { it(`should check the first request can't be edited as its state is different to new`, async() => {
await page.waitForClassPresent(selectors.ticketRequests.firstRequestQuantity, 'disabled'); await page.waitForClassPresent(selectors.ticketRequests.firstRequestQuantity, 'disabled');
const result = await page.isDisabled(selectors.ticketRequests.firstRequestQuantity); const result = await page.isDisabled(selectors.ticketRequests.firstRequestQuantity);
expect(result).toBe(true); expect(result).toBe(true);
}); });
it(`should confirm second request can't be edited as its state is different to new`, async() => { it(`should check the second request can't be edited as its state is different to new`, async() => {
await page.waitForClassPresent(selectors.ticketRequests.secondRequestQuantity, 'disabled'); await page.waitForClassPresent(selectors.ticketRequests.secondRequestQuantity, 'disabled');
const result = await page.isDisabled(selectors.ticketRequests.secondRequestQuantity); const result = await page.isDisabled(selectors.ticketRequests.secondRequestQuantity);
@ -70,7 +70,7 @@ describe('Ticket purchase request path', () => {
expect(message.type).toBe('success'); expect(message.type).toBe('success');
}); });
it('should confirm the request was deleted', async() => { it('should check the request was deleted', async() => {
await page.reloadSection('ticket.card.request.index'); await page.reloadSection('ticket.card.request.index');
await page.wait(selectors.ticketRequests.addRequestButton); await page.wait(selectors.ticketRequests.addRequestButton);
await page.waitForSelector(selectors.ticketRequests.thirdDescription, {hidden: true}); await page.waitForSelector(selectors.ticketRequests.thirdDescription, {hidden: true});

View File

@ -83,7 +83,7 @@ module.exports = Self => {
}); });
await models.Chat.sendCheckingPresence(ctx, requesterId, message); await models.Chat.sendCheckingPresence(ctx, requesterId, message);
// loguejar // log
let logRecord = { let logRecord = {
originFk: sale.ticketFk, originFk: sale.ticketFk,
userFk: userId, userFk: userId,

View File

@ -1,7 +1,6 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
// #2512 confirm.spec pollutes other tests describe('ticket-request confirm()', () => {
xdescribe('ticket-request confirm()', () => {
let ctx = { let ctx = {
req: { req: {
accessToken: {userId: 9}, accessToken: {userId: 9},
@ -83,37 +82,4 @@ xdescribe('ticket-request confirm()', () => {
// restores // restores
await request.updateAttributes({saleFk: null}); await request.updateAttributes({saleFk: null});
}); });
it(`should create a new sale for the the request if there's no sale id`, async() => {
const requestId = 4;
const itemId = 1;
const quantity = 10;
const originalRequest = await app.models.TicketRequest.findById(requestId);
ctx.args = {
itemFk: itemId,
id: requestId,
quantity: quantity
};
const request = await app.models.TicketRequest.findById(requestId);
await request.updateAttributes({saleFk: null});
await app.models.TicketRequest.confirm(ctx);
const updatedRequest = await app.models.TicketRequest.findById(requestId);
const createdSaleId = updatedRequest.saleFk;
expect(updatedRequest.saleFk).toEqual(createdSaleId);
expect(updatedRequest.isOk).toEqual(true);
expect(updatedRequest.itemFk).toEqual(itemId);
// restores
await originalRequest.updateAttributes(originalRequest);
await app.models.Sale.destroyById(createdSaleId);
await app.models.Item.rawSql(`
TRUNCATE TABLE cache.last_buy
`);
});
}); });