2018-09-05 09:34:23 +00:00
|
|
|
import './index.js';
|
2018-12-27 11:54:16 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-09-05 09:34:23 +00:00
|
|
|
|
|
|
|
describe('claim', () => {
|
2018-09-25 12:37:35 +00:00
|
|
|
describe('Component vnClaimAction', () => {
|
2018-09-05 09:34:23 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('claim'));
|
2018-09-05 09:34:23 +00:00
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
2018-09-05 09:34:23 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = 1;
|
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
controller = $componentController('vnClaimAction', {$element: null});
|
2018-09-05 09:34:23 +00:00
|
|
|
controller.claim = {ticketFk: 1};
|
|
|
|
controller.$.model = {refresh: () => {}};
|
|
|
|
controller.$.addSales = {
|
|
|
|
hide: () => {},
|
|
|
|
show: () => {}
|
|
|
|
};
|
2018-10-02 07:52:38 +00:00
|
|
|
controller.$.lastTicketsModel = crudModel;
|
|
|
|
controller.$.lastTicketsPopover = {
|
|
|
|
hide: () => {},
|
|
|
|
show: () => {}
|
|
|
|
};
|
2018-10-08 05:31:55 +00:00
|
|
|
controller.card = {reload: () => {}};
|
2020-05-15 12:47:19 +00:00
|
|
|
$httpBackend.expectGET(`ClaimStates/findOne`).respond({});
|
2018-09-05 09:34:23 +00:00
|
|
|
}));
|
|
|
|
|
2020-05-15 12:47:19 +00:00
|
|
|
describe('getResolvedState()', () => {
|
|
|
|
it('should return the resolved state id', () => {
|
|
|
|
$httpBackend.expectGET(`ClaimStates/findOne`).respond({id: 1});
|
|
|
|
controller.getResolvedState();
|
2018-09-05 09:34:23 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-05-15 12:47:19 +00:00
|
|
|
expect(controller.resolvedStateId).toEqual(1);
|
2018-09-05 09:34:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-24 10:12:36 +00:00
|
|
|
describe('calculateTotals()', () => {
|
|
|
|
it('should calculate the total price of the items claimed', () => {
|
|
|
|
controller.salesClaimed = [
|
|
|
|
{sale: {quantity: 5, price: 2, discount: 0}},
|
|
|
|
{sale: {quantity: 10, price: 2, discount: 0}},
|
|
|
|
{sale: {quantity: 10, price: 2, discount: 0}}
|
|
|
|
];
|
|
|
|
controller.calculateTotals();
|
|
|
|
|
|
|
|
expect(controller.claimedTotal).toEqual(50);
|
|
|
|
});
|
|
|
|
});
|
2018-09-25 12:37:35 +00:00
|
|
|
|
|
|
|
describe('importToNewRefundTicket()', () => {
|
2018-11-23 13:30:01 +00:00
|
|
|
it('should perform a post query and add lines from a new ticket', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.model, 'refresh');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2020-05-15 12:47:19 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
|
2018-09-25 12:37:35 +00:00
|
|
|
controller.importToNewRefundTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalled();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2018-09-25 12:37:35 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-02 07:52:38 +00:00
|
|
|
|
|
|
|
describe('showLastTickets()', () => {
|
|
|
|
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.lastTicketsModel, 'refresh');
|
|
|
|
jest.spyOn(controller.$.lastTicketsPopover, 'show');
|
2020-05-15 12:47:19 +00:00
|
|
|
|
2018-10-02 07:52:38 +00:00
|
|
|
controller.showLastTickets({});
|
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalled();
|
|
|
|
expect(controller.$.lastTicketsPopover.show).toHaveBeenCalled();
|
2018-10-02 07:52:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('importTicketLines()', () => {
|
2018-11-23 13:30:01 +00:00
|
|
|
it('should perform a post query and add lines from an existent ticket', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.model, 'refresh');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$.lastTicketsPopover, 'hide');
|
2020-05-15 12:47:19 +00:00
|
|
|
|
2018-10-02 07:52:38 +00:00
|
|
|
let data = {claimFk: 1, ticketFk: 1};
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({});
|
2018-10-02 07:52:38 +00:00
|
|
|
controller.importTicketLines(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
expect(controller.$.lastTicketsPopover.hide).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-10-08 05:31:55 +00:00
|
|
|
|
|
|
|
describe('regularize()', () => {
|
|
|
|
it('should perform a post query and reload the claim card', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2018-10-08 05:31:55 +00:00
|
|
|
|
2020-05-14 12:01:34 +00:00
|
|
|
$httpBackend.expect('POST', `Claims/1/regularizeClaim`).respond({});
|
2018-10-08 05:31:55 +00:00
|
|
|
controller.regularize();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
2019-04-16 06:09:16 +00:00
|
|
|
|
2020-05-14 12:01:34 +00:00
|
|
|
describe('save()', () => {
|
|
|
|
it('should perform a patch query and show a success message', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
const data = {hasToPickUp: true};
|
|
|
|
$httpBackend.expect('PATCH', `Claims/1/updateClaimAction`, data).respond({});
|
|
|
|
controller.save(data);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-05-14 12:01:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
describe('onUpdateGreugeAccept()', () => {
|
2019-12-20 09:40:12 +00:00
|
|
|
const greugeTypeId = 7;
|
|
|
|
const freightPickUpPrice = 11;
|
2019-04-16 06:09:16 +00:00
|
|
|
|
2019-12-20 08:30:35 +00:00
|
|
|
it('should make a query and get the greugeTypeId and greuge config', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2019-12-19 10:37:53 +00:00
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
$httpBackend.expectRoute('GET', `GreugeTypes/findOne`).respond({id: greugeTypeId});
|
|
|
|
$httpBackend.expectGET(`GreugeConfigs/findOne`).respond({freightPickUpPrice});
|
|
|
|
controller.onUpdateGreugeAccept();
|
2019-04-16 06:09:16 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-12-20 09:40:12 +00:00
|
|
|
expect(controller.greugeTypeFreightId).toEqual(greugeTypeId);
|
|
|
|
expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice);
|
2019-04-16 06:09:16 +00:00
|
|
|
});
|
2019-12-20 08:30:35 +00:00
|
|
|
|
|
|
|
// #1957 - Investigate how to test nested httpBackend requests
|
|
|
|
xit('should perform a insert into greuges', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2019-12-20 08:30:35 +00:00
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => {
|
2019-12-20 09:40:12 +00:00
|
|
|
return resolve({id: greugeTypeId});
|
2019-12-20 08:30:35 +00:00
|
|
|
}));
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => {
|
2019-12-20 09:40:12 +00:00
|
|
|
return resolve({freightPickUpPrice});
|
2019-12-20 08:30:35 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
controller.claim.clientFk = 101;
|
|
|
|
controller.claim.id = 11;
|
|
|
|
let data = {
|
|
|
|
clientFk: 101,
|
|
|
|
description: `claim: ${controller.claim.id}`,
|
2019-12-20 09:40:12 +00:00
|
|
|
amount: freightPickUpPrice,
|
|
|
|
greugeTypeFk: greugeTypeId,
|
2019-12-20 08:30:35 +00:00
|
|
|
ticketFk: controller.claim.ticketFk
|
|
|
|
};
|
|
|
|
$httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => {
|
2019-12-20 09:40:12 +00:00
|
|
|
return resolve({id: freightPickUpPrice});
|
2019-12-20 08:30:35 +00:00
|
|
|
}));
|
2020-05-19 08:51:50 +00:00
|
|
|
controller.onUpdateGreugeAccept().then(res => {
|
2020-01-22 08:04:26 +00:00
|
|
|
|
2019-12-20 08:30:35 +00:00
|
|
|
}).catch(error => {
|
2020-01-22 08:04:26 +00:00
|
|
|
|
2019-12-20 08:30:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
2019-04-16 06:09:16 +00:00
|
|
|
});
|
2018-09-05 09:34:23 +00:00
|
|
|
});
|
|
|
|
});
|