salix/modules/claim/front/action/index.spec.js

156 lines
6.2 KiB
JavaScript
Raw Normal View History

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', () => {
describe('Component vnClaimAction', () => {
2018-09-05 09:34:23 +00:00
let controller;
let $httpBackend;
let $state;
beforeEach(ngModule('claim'));
2018-09-05 09:34:23 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(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: () => {}
};
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);
});
});
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
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
controller.importToNewRefundTicket();
$httpBackend.flush();
2020-05-19 08:51:50 +00:00
expect(controller.$.model.refresh).toHaveBeenCalled();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
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).toHaveBeenCalled();
2018-10-08 05:31:55 +00:00
});
});
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-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
2020-10-06 12:32:24 +00:00
it('should perform a insert into greuges', done => {
jest.spyOn(controller, 'getGreugeTypeId').mockReturnValue(new Promise(resolve => {
2019-12-20 09:40:12 +00:00
return resolve({id: greugeTypeId});
2019-12-20 08:30:35 +00:00
}));
2020-10-06 12:32:24 +00:00
jest.spyOn(controller, 'getGreugeConfig').mockReturnValue(new Promise(resolve => {
2019-12-20 09:40:12 +00:00
return resolve({freightPickUpPrice});
2019-12-20 08:30:35 +00:00
}));
2020-10-06 12:32:24 +00:00
jest.spyOn(controller, 'updateGreuge').mockReturnValue(new Promise(resolve => {
return resolve(true);
}));
2019-12-20 08:30:35 +00:00
controller.claim.clientFk = 1101;
2019-12-20 08:30:35 +00:00
controller.claim.id = 11;
2020-10-06 12:32:24 +00:00
controller.onUpdateGreugeAccept().then(() => {
expect(controller.updateGreuge).toHaveBeenCalledWith(jasmine.any(Object));
done();
}).catch(done.fail);
});
});
describe('updateGreuge()', () => {
2020-10-06 12:37:03 +00:00
it('should make a query and then call to showSuccess() and showMessage() methods', () => {
2020-10-06 12:32:24 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.vnApp, 'showMessage');
const freightPickUpPrice = 11;
const greugeTypeId = 7;
const expectedData = {
clientFk: 1101,
2019-12-20 08:30:35 +00:00
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
};
2020-10-06 12:32:24 +00:00
$httpBackend.expect('POST', `Greuges`, expectedData).respond(200);
controller.updateGreuge(expectedData);
2019-12-20 08:30:35 +00:00
$httpBackend.flush();
2020-10-06 12:32:24 +00:00
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Greuge added');
2019-12-20 08:30:35 +00:00
});
2019-04-16 06:09:16 +00:00
});
2018-09-05 09:34:23 +00:00
});
});