2020-11-10 09:38:25 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Ticket Component vnTicketDescriptorMenu', () => {
|
|
|
|
let $httpBackend;
|
2021-10-07 11:36:23 +00:00
|
|
|
let $httpParamSerializer;
|
2020-11-10 09:38:25 +00:00
|
|
|
let controller;
|
|
|
|
let $state;
|
|
|
|
|
|
|
|
const ticket = {
|
|
|
|
id: 16,
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2020-11-10 09:38:25 +00:00
|
|
|
invoiceOut: {id: 1},
|
|
|
|
client: {
|
2021-06-23 11:24:23 +00:00
|
|
|
id: 1101,
|
2020-11-10 09:38:25 +00:00
|
|
|
email: 'client@email'
|
|
|
|
},
|
|
|
|
address: {
|
2021-06-23 11:24:23 +00:00
|
|
|
id: 1101,
|
2020-11-10 09:38:25 +00:00
|
|
|
mobile: 111111111,
|
|
|
|
phone: 2222222222
|
|
|
|
},
|
|
|
|
tracking: {
|
|
|
|
state: {alertLevel: 3}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_, _$state_) => {
|
2020-11-10 09:38:25 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2021-10-07 11:36:23 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2020-11-10 09:38:25 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = 16;
|
|
|
|
$state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
|
|
|
|
|
|
|
|
const $element = angular.element('<vn-ticket-descriptor-menu></vn-ticket-descriptor-menu>');
|
|
|
|
controller = $componentController('vnTicketDescriptorMenu', {$element});
|
|
|
|
controller._ticketId = ticket.id;
|
|
|
|
controller._id = ticket.id;
|
|
|
|
controller.ticket = ticket;
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('addTurn()', () => {
|
2024-03-20 20:14:01 +00:00
|
|
|
pending('refs #6302');
|
2020-11-10 09:38:25 +00:00
|
|
|
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
|
|
|
|
controller.$.addTurn = {hide: () => {}};
|
|
|
|
jest.spyOn(controller.$.addTurn, 'hide');
|
|
|
|
|
|
|
|
$httpBackend.expectPATCH(`TicketWeeklies`).respond();
|
|
|
|
controller.addTurn(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.addTurn.hide).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteTicket()', () => {
|
|
|
|
it('should make a query and call vnApp.showSuccess()', () => {
|
2022-01-20 10:06:15 +00:00
|
|
|
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
|
|
|
|
controller.deleteTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.reload).toHaveBeenCalled();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should make a query and call showSuccess() after state.go if the state wasn't inside ticket module`, () => {
|
2020-11-10 09:38:25 +00:00
|
|
|
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2022-01-20 10:06:15 +00:00
|
|
|
controller.$state.current.name = 'ticket.card.something';
|
2020-11-10 09:38:25 +00:00
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
|
|
|
|
controller.deleteTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.reload).toHaveBeenCalled();
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
describe('showPdfDeliveryNote()', () => {
|
2020-11-10 09:38:25 +00:00
|
|
|
it('should open a new window showing a delivery note PDF document', () => {
|
2021-10-07 11:36:23 +00:00
|
|
|
jest.spyOn(window, 'open').mockReturnThis();
|
2022-03-22 06:38:14 +00:00
|
|
|
const type = 'deliveryNote';
|
2021-10-07 11:36:23 +00:00
|
|
|
const expectedParams = {
|
2022-03-22 06:38:14 +00:00
|
|
|
recipientId: ticket.client.id,
|
|
|
|
type: type
|
2020-11-10 09:38:25 +00:00
|
|
|
};
|
2021-10-07 11:36:23 +00:00
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
2022-10-04 05:41:40 +00:00
|
|
|
const expectedPath = `api/tickets/${ticket.id}/delivery-note-pdf?${serializedParams}`;
|
2022-03-22 06:38:14 +00:00
|
|
|
controller.showPdfDeliveryNote(type);
|
2020-11-10 09:38:25 +00:00
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
expect(window.open).toHaveBeenCalledWith(expectedPath);
|
2020-11-10 09:38:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
describe('sendPdfDeliveryNote()', () => {
|
2020-11-10 09:38:25 +00:00
|
|
|
it('should make a query and call vnApp.showMessage()', () => {
|
|
|
|
jest.spyOn(controller.vnEmail, 'send');
|
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
const $data = {email: 'brucebanner@gothamcity.com'};
|
2020-11-10 09:38:25 +00:00
|
|
|
const params = {
|
2023-05-18 12:44:05 +00:00
|
|
|
id: 16,
|
2021-10-07 11:36:23 +00:00
|
|
|
recipient: $data.email,
|
2022-10-04 05:41:40 +00:00
|
|
|
recipientId: ticket.client.id
|
2020-11-10 09:38:25 +00:00
|
|
|
};
|
2021-10-07 11:36:23 +00:00
|
|
|
controller.sendPdfDeliveryNote($data);
|
2020-11-10 09:38:25 +00:00
|
|
|
|
2022-10-04 05:41:40 +00:00
|
|
|
const expectedPath = `tickets/${ticket.id}/delivery-note-email`;
|
|
|
|
|
|
|
|
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params);
|
2020-11-10 09:38:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-08 07:51:42 +00:00
|
|
|
describe('showCsvDeliveryNote()', () => {
|
|
|
|
it('should make a query to the csv delivery-note download endpoint and show a message snackbar', () => {
|
|
|
|
jest.spyOn(window, 'open').mockReturnThis();
|
|
|
|
|
|
|
|
const expectedParams = {
|
|
|
|
recipientId: ticket.client.id
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
2022-10-04 05:41:40 +00:00
|
|
|
const expectedPath = `api/tickets/${ticket.id}/delivery-note-csv?${serializedParams}`;
|
2021-10-08 07:51:42 +00:00
|
|
|
controller.showCsvDeliveryNote();
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(expectedPath);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sendCsvDeliveryNote()', () => {
|
|
|
|
it('should make a query to the csv delivery-note send endpoint and show a message snackbar', () => {
|
2022-10-04 05:41:40 +00:00
|
|
|
jest.spyOn(controller.vnEmail, 'send');
|
2021-10-08 07:51:42 +00:00
|
|
|
|
|
|
|
const $data = {email: 'brucebanner@gothamcity.com'};
|
|
|
|
const expectedParams = {
|
|
|
|
recipient: $data.email,
|
|
|
|
recipientId: ticket.client.id,
|
|
|
|
};
|
|
|
|
controller.sendCsvDeliveryNote($data);
|
|
|
|
|
2022-10-04 05:41:40 +00:00
|
|
|
const expectedPath = `tickets/${ticket.id}/delivery-note-csv-email`;
|
|
|
|
|
|
|
|
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, expectedParams);
|
2021-10-08 07:51:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-10 09:38:25 +00:00
|
|
|
describe('makeInvoice()', () => {
|
|
|
|
it('should make a query and call $state.reload() method', () => {
|
|
|
|
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
2021-07-01 12:03:28 +00:00
|
|
|
const expectedParams = {ticketsIds: [ticket.id]};
|
2024-01-29 13:54:19 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/invoiceTicketsAndPdf`, expectedParams).respond();
|
2020-11-10 09:38:25 +00:00
|
|
|
controller.makeInvoice();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.reload).toHaveBeenCalledWith();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
2023-07-06 13:16:52 +00:00
|
|
|
|
|
|
|
it('should show withoutWeightConfirmation', () => {
|
|
|
|
controller.$.withoutWeightConfirmation = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.withoutWeightConfirmation, 'show');
|
|
|
|
controller.ticket.address.incotermsFk = true;
|
|
|
|
|
|
|
|
controller.makeInvoice();
|
|
|
|
controller.ticket.address.incotermsFk = false;
|
|
|
|
|
|
|
|
expect(controller.$.withoutWeightConfirmation.show).toHaveBeenCalled();
|
|
|
|
});
|
2020-11-10 09:38:25 +00:00
|
|
|
});
|
|
|
|
|
2021-10-07 11:36:23 +00:00
|
|
|
describe('createPdfInvoice()', () => {
|
2020-11-10 09:38:25 +00:00
|
|
|
it('should make a query and show a success snackbar', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
2022-02-21 07:48:53 +00:00
|
|
|
$httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond();
|
|
|
|
$httpBackend.whenGET(`Tickets/${ticket.id}`).respond();
|
2021-03-15 15:35:55 +00:00
|
|
|
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond();
|
2021-10-07 11:36:23 +00:00
|
|
|
controller.createPdfInvoice();
|
2020-11-10 09:38:25 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('changeShipped()', () => {
|
|
|
|
it('should make a query and change the shipped hour if the response is accept', () => {
|
|
|
|
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond();
|
|
|
|
controller.changeShipped();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.reload).toHaveBeenCalled();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('recalculateComponents()', () => {
|
|
|
|
it('should make a query and show a success message', () => {
|
|
|
|
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expect('POST', `Tickets/${ticket.id}/recalculateComponents`).respond();
|
|
|
|
controller.recalculateComponents();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.reload).toHaveBeenCalled();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-14 11:40:50 +00:00
|
|
|
describe('refund()', () => {
|
2022-04-11 08:01:15 +00:00
|
|
|
it('should make a query and go to ticket.card.sale', () => {
|
2022-04-26 11:08:06 +00:00
|
|
|
controller.$state.go = jest.fn();
|
|
|
|
|
|
|
|
controller._id = ticket.id;
|
2022-04-25 08:10:59 +00:00
|
|
|
|
2022-07-14 11:40:50 +00:00
|
|
|
const params = {
|
|
|
|
ticketsIds: [16]
|
2022-04-25 08:10:59 +00:00
|
|
|
};
|
2023-11-30 14:16:41 +00:00
|
|
|
const response = {id: 99};
|
|
|
|
$httpBackend.expectPOST('Tickets/refund', params).respond([response]);
|
2022-04-25 08:10:59 +00:00
|
|
|
controller.refund();
|
2022-04-04 11:56:36 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2023-11-30 14:16:41 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', response);
|
2022-04-04 11:56:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-25 11:16:01 +00:00
|
|
|
describe('sendChangesSms()', () => {
|
|
|
|
it('should make a query and open the sms dialog', () => {
|
|
|
|
controller.$.sms = {open: () => {}};
|
|
|
|
jest.spyOn(controller.$.sms, 'open');
|
|
|
|
|
|
|
|
$httpBackend.expectGET(`TicketLogs/${ticket.id}/getChanges`).respond();
|
|
|
|
controller.sendChangesSms();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.sms.open).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-10 09:38:25 +00:00
|
|
|
describe('showSMSDialog()', () => {
|
|
|
|
it('should set the destionationFk and destination properties and then call the sms open() method', () => {
|
|
|
|
controller.$.sms = {open: () => {}};
|
|
|
|
controller.showSMSDialog();
|
|
|
|
|
|
|
|
expect(controller.newSMS).toEqual({
|
|
|
|
destinationFk: ticket.clientFk,
|
|
|
|
destination: ticket.address.mobile,
|
|
|
|
ticketId: 16
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-02-21 07:48:53 +00:00
|
|
|
|
|
|
|
describe('hasDocuware()', () => {
|
|
|
|
it('should call hasDocuware method', () => {
|
2023-01-13 12:33:59 +00:00
|
|
|
$httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(true);
|
2022-02-21 07:48:53 +00:00
|
|
|
controller.hasDocuware();
|
|
|
|
$httpBackend.flush();
|
2023-01-13 12:33:59 +00:00
|
|
|
|
|
|
|
expect(controller.hasDocuwareFile).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('uploadDocuware()', () => {
|
|
|
|
it('should open dialog if not force', () => {
|
|
|
|
controller.$.pdfToTablet = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.pdfToTablet, 'show');
|
|
|
|
controller.uploadDocuware(false);
|
|
|
|
|
|
|
|
expect(controller.$.pdfToTablet.show).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2023-06-12 13:20:46 +00:00
|
|
|
it('should make a query', () => {
|
2023-01-13 12:33:59 +00:00
|
|
|
controller.$.balanceCreate = {show: () => {}};
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
2023-06-13 09:37:35 +00:00
|
|
|
$httpBackend.whenPOST(`Docuwares/upload`).respond(true);
|
2023-01-13 12:33:59 +00:00
|
|
|
controller.uploadDocuware(true);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2022-02-21 07:48:53 +00:00
|
|
|
});
|
|
|
|
});
|
2020-11-10 09:38:25 +00:00
|
|
|
});
|