6745-2404_testToMaster #1950
|
@ -1,123 +0,0 @@
|
||||||
const app = require('vn-loopback/server/server');
|
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
||||||
|
|
||||||
// 2277 solucionar problema al testear procedimiento con start transaction / rollback
|
|
||||||
xdescribe('ticket_componentMakeUpdate()', () => {
|
|
||||||
it('should recalculate the ticket components without make modifications', async() => {
|
|
||||||
let stmts = [];
|
|
||||||
let stmt;
|
|
||||||
|
|
||||||
let params = {
|
|
||||||
ticketId: 11,
|
|
||||||
clientId: 1102,
|
|
||||||
agencyModeId: 2,
|
|
||||||
addressId: 122,
|
|
||||||
zoneId: 3,
|
|
||||||
warehouseId: 1,
|
|
||||||
companyId: 442,
|
|
||||||
isDeleted: 0,
|
|
||||||
hasToBeUnrouted: 0,
|
|
||||||
componentOption: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
stmts.push('START TRANSACTION');
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [
|
|
||||||
params.ticketId
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
let originalTicketIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, DATE_ADD(CURDATE(), INTERVAL +1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY), ?, ?, ?)', [
|
|
||||||
params.ticketId,
|
|
||||||
params.clientId,
|
|
||||||
params.agencyModeId,
|
|
||||||
params.addressId,
|
|
||||||
params.zoneId,
|
|
||||||
params.warehouseId,
|
|
||||||
params.companyId,
|
|
||||||
params.isDeleted,
|
|
||||||
params.hasToBeUnrouted,
|
|
||||||
params.componentOption
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [
|
|
||||||
params.ticketId
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
let updatedTicketIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
stmts.push('ROLLBACK');
|
|
||||||
|
|
||||||
let sql = ParameterizedSQL.join(stmts, ';');
|
|
||||||
let result = await app.models.Ticket.rawStmt(sql);
|
|
||||||
|
|
||||||
let originalTicketData = result[originalTicketIndex];
|
|
||||||
let updatedTicketData = result[updatedTicketIndex];
|
|
||||||
|
|
||||||
expect(originalTicketData[0].isDeleted).toEqual(updatedTicketData[0].isDeleted);
|
|
||||||
expect(originalTicketData[0].routeFk).toEqual(updatedTicketData[0].routeFk);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete and unroute a ticket and recalculate the components', async() => {
|
|
||||||
let stmts = [];
|
|
||||||
let stmt;
|
|
||||||
|
|
||||||
let params = {
|
|
||||||
ticketId: 11,
|
|
||||||
clientId: 1102,
|
|
||||||
agencyModeId: 2,
|
|
||||||
addressId: 122,
|
|
||||||
zoneId: 3,
|
|
||||||
warehouseId: 1,
|
|
||||||
companyId: 442,
|
|
||||||
isDeleted: 1,
|
|
||||||
hasToBeUnrouted: 1,
|
|
||||||
componentOption: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
stmts.push('START TRANSACTION');
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [
|
|
||||||
params.ticketId
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
let originalTicketIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, DATE_ADD(CURDATE(), INTERVAL +1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY), ?, ?, ?)', [
|
|
||||||
params.ticketId,
|
|
||||||
params.clientId,
|
|
||||||
params.agencyModeId,
|
|
||||||
params.addressId,
|
|
||||||
params.zoneId,
|
|
||||||
params.warehouseId,
|
|
||||||
params.companyId,
|
|
||||||
params.isDeleted,
|
|
||||||
params.hasToBeUnrouted,
|
|
||||||
params.componentOption
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [
|
|
||||||
params.ticketId
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
let updatedTicketIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
stmts.push('ROLLBACK');
|
|
||||||
|
|
||||||
let sql = ParameterizedSQL.join(stmts, ';');
|
|
||||||
let result = await app.models.Ticket.rawStmt(sql);
|
|
||||||
|
|
||||||
let originalTicketData = result[originalTicketIndex];
|
|
||||||
let updatedTicketData = result[updatedTicketIndex];
|
|
||||||
|
|
||||||
expect(originalTicketData[0].isDeleted).not.toEqual(updatedTicketData[0].isDeleted);
|
|
||||||
expect(originalTicketData[0].routeFk).not.toEqual(updatedTicketData[0].routeFk);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -56,63 +56,6 @@ describe('Worker time control path', () => {
|
||||||
expect(result).toContain(month);
|
expect(result).toContain(month);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return error when insert 'out' of first entry`, async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
|
||||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm);
|
|
||||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
|
||||||
await page.respondToDialog('accept');
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should insert 'in' monday`, async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
|
||||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm);
|
|
||||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
|
||||||
await page.respondToDialog('accept');
|
|
||||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toEqual(eightAm);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should insert 'out' monday`, async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
|
||||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, fourPm);
|
|
||||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
|
||||||
await page.respondToDialog('accept');
|
|
||||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfMonday, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toEqual(fourPm);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should check Hank Pym worked 8:20 hours`, async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
await page.waitForTextInElement(selectors.workerTimeControl.mondayWorkedHours, '08:20 h.');
|
|
||||||
await page.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '08:20 h.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove first entry of monday', async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
await page.waitForTextInElement(selectors.workerTimeControl.firstEntryOfMonday, eightAm);
|
|
||||||
await page.waitForTextInElement(selectors.workerTimeControl.secondEntryOfMonday, fourPm);
|
|
||||||
await page.waitToClick(selectors.workerTimeControl.firstEntryOfMondayDelete);
|
|
||||||
await page.respondToDialog('accept');
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Entry removed');
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should be the 'out' the first entry of monday`, async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/4707');
|
|
||||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toEqual(fourPm);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change week of month', async() => {
|
it('should change week of month', async() => {
|
||||||
await page.click(selectors.workerTimeControl.thrirdWeekDay);
|
await page.click(selectors.workerTimeControl.thrirdWeekDay);
|
||||||
const result = await page.getProperty(selectors.workerTimeControl.mondayWorkedHours, 'innerText');
|
const result = await page.getProperty(selectors.workerTimeControl.mondayWorkedHours, 'innerText');
|
||||||
|
|
|
@ -188,17 +188,6 @@ describe('Ticket Edit sale path', () => {
|
||||||
expect(result).toContain('22.50');
|
expect(result).toContain('22.50');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check in the history that logs has been added', async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/5455');
|
|
||||||
await page.reload({waitUntil: ['networkidle0', 'domcontentloaded']});
|
|
||||||
await page.waitToClick(selectors.ticketSales.firstSaleHistoryButton);
|
|
||||||
await page.waitForSelector(selectors.ticketSales.firstSaleHistory);
|
|
||||||
const result = await page.countElement(selectors.ticketSales.firstSaleHistory);
|
|
||||||
|
|
||||||
expect(result).toBeGreaterThan(0);
|
|
||||||
await page.waitToClick(selectors.ticketSales.closeHistory);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should recalculate price of sales', async() => {
|
it('should recalculate price of sales', async() => {
|
||||||
await page.waitToClick(selectors.ticketSales.firstSaleCheckbox);
|
await page.waitToClick(selectors.ticketSales.firstSaleCheckbox);
|
||||||
await page.waitToClick(selectors.ticketSales.secondSaleCheckbox);
|
await page.waitToClick(selectors.ticketSales.secondSaleCheckbox);
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
import selectors from '../../helpers/selectors.js';
|
|
||||||
import getBrowser from '../../helpers/puppeteer';
|
|
||||||
|
|
||||||
// #2221 Local MySQL8 crashes when rest method Items/getBalance is called
|
|
||||||
xdescribe('Ticket diary path', () => {
|
|
||||||
let page;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
|
||||||
page = (await getBrowser()).page;
|
|
||||||
await page.loginAndModule('employee', 'ticket');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async() => {
|
|
||||||
await page.browser().close();
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should navigate to item diary from ticket sale and check the lines`, async() => {
|
|
||||||
await page.accessToSearchResult('1');
|
|
||||||
await page.waitToClick(selectors.ticketSummary.firstSaleItemId);
|
|
||||||
await page.waitToClick(selectors.ticketSummary.popoverDiaryButton);
|
|
||||||
await page.waitForState('item.card.diary');
|
|
||||||
|
|
||||||
const secondIdClass = await page.getClassName(selectors.itemDiary.secondTicketId);
|
|
||||||
const fourthBalanceClass = await page.getClassName(selectors.itemDiary.fourthBalance);
|
|
||||||
const firstBalanceClass = await page.getClassName(selectors.itemDiary.firstBalance);
|
|
||||||
|
|
||||||
expect(secondIdClass).toContain('message');
|
|
||||||
expect(fourthBalanceClass).toContain('message');
|
|
||||||
expect(firstBalanceClass).toContain('balance');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,114 +0,0 @@
|
||||||
import selectors from '../../helpers/selectors.js';
|
|
||||||
import getBrowser from '../../helpers/puppeteer.js';
|
|
||||||
|
|
||||||
// #1528 e2e claim/detail
|
|
||||||
xdescribe('Claim detail', () => {
|
|
||||||
let browser;
|
|
||||||
let page;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
|
||||||
browser = await getBrowser();
|
|
||||||
page = browser.page;
|
|
||||||
await page.loginAndModule('salesPerson', 'claim');
|
|
||||||
await page.accessToSearchResult('1');
|
|
||||||
await page.accessToSection('claim.card.detail');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async() => {
|
|
||||||
await browser.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add the first claimable item from ticket to the claim', async() => {
|
|
||||||
await page.waitToClick(selectors.claimDetail.addItemButton);
|
|
||||||
await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket);
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should confirm the claim contains now two items', async() => {
|
|
||||||
const result = await page.countElement(selectors.claimDetail.claimDetailLine);
|
|
||||||
|
|
||||||
expect(result).toEqual(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should edit de first item claimed quantity', async() => {
|
|
||||||
await page.clearInput(selectors.claimDetail.firstItemQuantityInput); // selector deleted, find new upon fixes
|
|
||||||
await page.write(selectors.claimDetail.firstItemQuantityInput, '4'); // selector deleted, find new upon fixes
|
|
||||||
await page.keyboard.press('Enter');
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should confirm the first item quantity, and the claimed total were correctly edited', async() => {
|
|
||||||
const claimedQuantity = page
|
|
||||||
.waitToGetProperty(selectors.claimDetail.firstItemQuantityInput, 'value'); // selector deleted, find new upon fixes
|
|
||||||
|
|
||||||
const totalClaimed = page
|
|
||||||
.waitToGetProperty(selectors.claimDetail.totalClaimed, 'innerText');
|
|
||||||
|
|
||||||
expect(claimedQuantity).toEqual('4');
|
|
||||||
expect(totalClaimed).toContain('€47.62');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should login as salesAssistant and navigate to the claim.detail section', async() => {
|
|
||||||
await page.loginAndModule('salesAssistant', 'claim');
|
|
||||||
await page.accessToSearchResult('1');
|
|
||||||
await page.accessToSection('claim.card.detail');
|
|
||||||
let url = await page.expectURL('/detail'); // replace with waitForState
|
|
||||||
|
|
||||||
expect(url).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should edit de second item claimed discount', async() => {
|
|
||||||
await page.waitToClick(selectors.claimDetail.secondItemDiscount);
|
|
||||||
await page.write(selectors.claimDetail.discount, '100');
|
|
||||||
await page.keyboard.press('Enter');
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should check the mana is the expected one', async() => {
|
|
||||||
await page.waitToClick(selectors.claimDetail.secondItemDiscount);
|
|
||||||
const result = await page.waitToGetProperty(selectors.claimDetail.discoutPopoverMana, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toContain('MANÁ: €106');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete the second item from the claim', async() => {
|
|
||||||
await page.waitToClick(selectors.claimDetail.secondItemDeleteButton);
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should confirm the claim contains now one item', async() => {
|
|
||||||
const result = await page.countElement(selectors.claimDetail.claimDetailLine);
|
|
||||||
|
|
||||||
expect(result).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add the deleted ticket from to the claim', async() => {
|
|
||||||
await page.waitToClick(selectors.claimDetail.addItemButton);
|
|
||||||
await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket);
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should have been redirected to the next section in claims`, async() => {
|
|
||||||
let url = await page.expectURL('development'); // replace with waitForState
|
|
||||||
|
|
||||||
expect(url).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should navigate back to claim.detail to confirm the claim contains now two items', async() => {
|
|
||||||
await page.accessToSection('claim.card.detail');
|
|
||||||
await page.waitForSelector(selectors.claimDetail.claimDetailLine);
|
|
||||||
const result = await page.countElement(selectors.claimDetail.claimDetailLine);
|
|
||||||
|
|
||||||
expect(result).toEqual(2);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -105,17 +105,4 @@ describe('Travel basic data path', () => {
|
||||||
it(`should check the received checkbox was saved even tho it doesn't make sense`, async() => {
|
it(`should check the received checkbox was saved even tho it doesn't make sense`, async() => {
|
||||||
await page.waitForClassPresent(selectors.travelBasicData.received, 'checked');
|
await page.waitForClassPresent(selectors.travelBasicData.received, 'checked');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate to the travel logs', async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/5455');
|
|
||||||
await page.accessToSection('travel.card.log');
|
|
||||||
await page.waitForState('travel.card.log');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should check the 1st log contains details from the changes made', async() => {
|
|
||||||
pending('https://redmine.verdnatura.es/issues/5455');
|
|
||||||
const result = await page.waitToGetProperty(selectors.travelLog.firstLogFirstTD, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toContain('new reference!');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,18 +33,6 @@ describe('Component vnTreeview', () => {
|
||||||
$element.remove();
|
$element.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
// See how to test DOM element in Jest
|
|
||||||
xdescribe('undrop()', () => {
|
|
||||||
it(`should reset all drop events and properties`, () => {
|
|
||||||
controller.dropping = angular.element(`<vn-treeview-child class="dropping"></vn-treeview-child>`);
|
|
||||||
jest.spyOn(controller.dropping.classList, 'remove');
|
|
||||||
|
|
||||||
controller.undrop();
|
|
||||||
|
|
||||||
expect(controller.dropping).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('dragOver()', () => {
|
describe('dragOver()', () => {
|
||||||
it(`should set the dragClientY property`, () => {
|
it(`should set the dragClientY property`, () => {
|
||||||
const event = new Event('dragover');
|
const event = new Event('dragover');
|
||||||
|
|
|
@ -120,7 +120,7 @@ module.exports = Self => {
|
||||||
observationTypeFk: obsevationType.id
|
observationTypeFk: obsevationType.id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
await models.TicketTracking.create({
|
await models.Ticket.state(ctx, {
|
||||||
ticketFk: newRefundTicket.id,
|
ticketFk: newRefundTicket.id,
|
||||||
stateFk: state.id,
|
stateFk: state.id,
|
||||||
userFk: worker.id
|
userFk: worker.id
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
xdescribe('boxing getVideo()', () => {
|
|
||||||
it('should return data', async() => {
|
|
||||||
const tx = await models.PackingSiteConfig.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const id = 1;
|
|
||||||
const video = 'video.mp4';
|
|
||||||
|
|
||||||
const response = {
|
|
||||||
pipe: () => {},
|
|
||||||
on: () => {},
|
|
||||||
end: () => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
headers: 'apiHeader',
|
|
||||||
data: {
|
|
||||||
pipe: () => {},
|
|
||||||
on: () => {},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
spyOn(https, 'request').and.returnValue(response);
|
|
||||||
|
|
||||||
const result = await models.Boxing.getVideo(id, video, req, null, options);
|
|
||||||
|
|
||||||
expect(result[0]).toEqual(response.data.videos[0].filename);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -49,7 +49,7 @@ module.exports = Self => {
|
||||||
for (const id of ticketIds) {
|
for (const id of ticketIds) {
|
||||||
const promise = await models.Ticket.state(ctx, {
|
const promise = await models.Ticket.state(ctx, {
|
||||||
stateFk: state.id,
|
stateFk: state.id,
|
||||||
workerFk: worker.id,
|
userFk: worker.id,
|
||||||
ticketFk: id
|
ticketFk: id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
|
|
|
@ -130,7 +130,17 @@ module.exports = Self => {
|
||||||
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions);
|
|
||||||
|
const deliveryState = await models.State.find({
|
||||||
|
where: {
|
||||||
|
code: 'DELIVERED'
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
await models.Ticket.state(ctx, {
|
||||||
|
ticketFk: ticketId,
|
||||||
|
stateFk: deliveryState.id
|
||||||
|
}, myOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -45,9 +45,8 @@ describe('ticket state()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
activeCtx.accessToken.userId = salesPersonId;
|
activeCtx.accessToken.userId = salesPersonId;
|
||||||
const params = {ticketFk: 2, stateFk: 3};
|
|
||||||
|
|
||||||
await models.Ticket.state(ctx, params, options);
|
await models.Ticket.state(ctx, {ticketFk: 2, stateFk: 3}, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -67,9 +66,8 @@ describe('ticket state()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
activeCtx.accessToken.userId = employeeId;
|
activeCtx.accessToken.userId = employeeId;
|
||||||
const params = {ticketFk: 11, stateFk: 13};
|
|
||||||
|
|
||||||
await models.Ticket.state(ctx, params, options);
|
await models.Ticket.state(ctx, {ticketFk: 11, stateFk: 13}, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -7,7 +7,6 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'data',
|
arg: 'data',
|
||||||
description: 'Model instance data',
|
|
||||||
type: 'Object',
|
type: 'Object',
|
||||||
required: true,
|
required: true,
|
||||||
http: {source: 'body'}
|
http: {source: 'body'}
|
||||||
|
@ -37,25 +36,21 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
|
|
||||||
if (!params.stateFk && !params.code)
|
if (!params.stateFk && !params.code)
|
||||||
throw new UserError('State cannot be blank');
|
throw new UserError('State cannot be blank');
|
||||||
|
|
||||||
if (params.code) {
|
if (params.stateFk) {
|
||||||
const state = await models.State.findOne({
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
where: {code: params.code},
|
params.code = code;
|
||||||
fields: ['id']
|
} else {
|
||||||
}, myOptions);
|
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
||||||
|
params.stateFk = id;
|
||||||
params.stateFk = state.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
const worker = await models.Worker.findOne({
|
const worker = await models.Worker.findOne({
|
||||||
where: {id: userId}
|
where: {id: ctx.req.accessToken.userId}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
params.userFk = worker.id;
|
params.userFk = worker.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,17 +58,21 @@ module.exports = Self => {
|
||||||
fields: ['stateFk']
|
fields: ['stateFk']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
let oldStateAllowed;
|
const oldStateAllowed = ticketState && await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
||||||
if (ticketState)
|
|
||||||
oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
|
||||||
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
||||||
|
|
||||||
const isAllowed = (!ticketState || oldStateAllowed == true) && newStateAllowed == true;
|
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
||||||
|
|
||||||
if (!isAllowed)
|
|
||||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||||
|
|
||||||
const ticketTracking = await models.TicketTracking.create(params, myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
||||||
|
|
||||||
|
const ticketTracking = await models.TicketTracking.findOne({
|
||||||
|
where: {ticketFk: params.ticketFk},
|
||||||
|
order: 'id DESC',
|
||||||
|
limit: 1
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
await ticketTracking.updateAttribute('userFk', params.userFk, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
for (ticket of ticketList) {
|
for (ticket of ticketList) {
|
||||||
if (ticket.ticketState().alertLevel == 0) {
|
if (ticket.ticketState().alertLevel == 0) {
|
||||||
promises.push(models.TicketTracking.create({
|
promises.push(models.Ticket.state(ctx, {
|
||||||
ticketFk: ticket.id,
|
ticketFk: ticket.id,
|
||||||
stateFk: fixingState.id,
|
stateFk: fixingState.id,
|
||||||
userFk: worker.id
|
userFk: worker.id
|
||||||
|
|
Loading…
Reference in New Issue