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

219 lines
9.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;
2019-12-19 10:37:53 +00:00
let $httpParamSerializer;
let $scope;
2018-09-05 09:34:23 +00:00
beforeEach(ngModule('claim'));
2018-09-05 09:34:23 +00:00
2019-12-19 10:37:53 +00:00
beforeEach(angular.mock.inject(($rootScope, $componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
$scope = $rootScope.$new();
2018-09-05 09:34:23 +00:00
$httpBackend = _$httpBackend_;
2019-12-19 10:37:53 +00:00
$httpParamSerializer = _$httpParamSerializer_;
2018-09-05 09:34:23 +00:00
$state = _$state_;
$state.params.id = 1;
2019-12-19 10:37:53 +00:00
controller = $componentController('vnClaimAction', {$state, $scope});
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: () => {}};
2018-09-05 09:34:23 +00:00
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
2018-09-24 10:12:36 +00:00
spyOn(controller, 'getClaimedSales');
2018-09-05 09:34:23 +00:00
spyOn(controller.$.addSales, 'show');
controller.openAddSalesDialog();
2018-09-24 10:12:36 +00:00
expect(controller.getClaimedSales).toHaveBeenCalledWith();
2018-09-05 09:34:23 +00:00
expect(controller.$.addSales.show).toHaveBeenCalledWith();
});
});
2018-09-24 10:12:36 +00:00
describe('getClaimedSales()', () => {
2018-09-05 09:34:23 +00:00
it('should make a query and set salesToClaim', () => {
2018-09-24 10:12:36 +00:00
controller.claim.id = 1;
$httpBackend.expectGET(`ClaimBeginnings/1`).respond(200, 1);
2018-09-24 10:12:36 +00:00
controller.getClaimedSales();
2018-09-05 09:34:23 +00:00
$httpBackend.flush();
2018-09-24 10:12:36 +00:00
expect(controller.claimedSales).toEqual(1);
2018-09-05 09:34:23 +00:00
});
});
describe('addClaimedSale(saleFk)', () => {
it('should make a post and call refresh, hide and showSuccess', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.$.addSales, 'hide');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`ClaimEnds/`).respond({});
2018-09-05 09:34:23 +00:00
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('deleteClaimedSale(id)', () => {
it('should make a delete and call refresh and showSuccess', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectDELETE(`ClaimEnds/1`).respond({});
2018-09-05 09:34:23 +00:00
controller.deleteClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
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', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
controller.importToNewRefundTicket();
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('showLastTickets()', () => {
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
spyOn(controller.$.lastTicketsModel, 'refresh');
spyOn(controller.$.lastTicketsPopover, 'show');
controller.showLastTickets({});
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith();
expect(controller.$.lastTicketsPopover.show).toHaveBeenCalledWith();
});
});
describe('importTicketLines()', () => {
2018-11-23 13:30:01 +00:00
it('should perform a post query and add lines from an existent ticket', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$.lastTicketsPopover, 'hide');
let data = {claimFk: 1, ticketFk: 1};
$httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({});
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', () => {
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
let data = {claimFk: $state.params.id};
$httpBackend.expect('POST', `Claims/regularizeClaim`, data).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
describe('onUpdateGreugeResponse()', () => {
2019-12-20 09:40:12 +00:00
const greugeTypeId = 7;
const freightPickUpPrice = 11;
2019-04-16 06:09:16 +00:00
it('should do nothing', () => {
2019-04-16 06:46:59 +00:00
spyOn(controller.$http, 'post');
2019-04-16 06:09:16 +00:00
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
2019-10-30 15:57:14 +00:00
controller.onUpdateGreugeResponse('cancel');
2019-04-16 06:09:16 +00:00
2019-04-16 06:46:59 +00:00
expect(controller.$http.post).not.toHaveBeenCalledWith();
2019-04-16 06:09:16 +00:00
expect(controller.card.reload).not.toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!');
});
2019-12-20 08:30:35 +00:00
it('should make a query and get the greugeTypeId and greuge config', () => {
2019-04-16 06:09:16 +00:00
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
2019-12-19 10:37:53 +00:00
const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}});
2019-12-20 09:40:12 +00:00
$httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId});
$httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice});
2019-10-30 15:57:14 +00:00
controller.onUpdateGreugeResponse('accept');
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', () => {
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
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
}));
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
}));
controller.onUpdateGreugeResponse('accept').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
});
});