2018-08-30 07:19:09 +00:00
|
|
|
import './index.js';
|
2018-12-27 11:54:16 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2018-09-05 11:01:21 +00:00
|
|
|
describe('claim', () => {
|
2018-08-30 07:19:09 +00:00
|
|
|
describe('Component vnClaimDetail', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2019-04-08 07:01:10 +00:00
|
|
|
let $state;
|
|
|
|
let aclService;
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2018-12-20 13:37:29 +00:00
|
|
|
beforeEach(ngModule('claim'));
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2019-04-08 07:01:10 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
2018-08-30 07:19:09 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpBackend.when('GET', 'claim/api/Claims/ClaimBeginnings').respond({});
|
2019-04-08 07:01:10 +00:00
|
|
|
$state = _$state_;
|
|
|
|
aclService = {hasAny: () => true};
|
|
|
|
controller = $componentController('vnClaimDetail', {$state, aclService});
|
2018-11-23 13:30:01 +00:00
|
|
|
controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}];
|
2018-12-20 13:37:29 +00:00
|
|
|
controller.salesClaimed = [{id: 1, sale: {}}];
|
2018-08-30 07:19:09 +00:00
|
|
|
controller.claim = {ticketFk: 1};
|
2019-06-12 06:19:02 +00:00
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$.addSales = {
|
2018-08-30 07:19:09 +00:00
|
|
|
hide: () => {},
|
|
|
|
show: () => {}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('openAddSalesDialog()', () => {
|
|
|
|
it('should call getClaimableFromTicket and $.addSales.show', () => {
|
|
|
|
controller.$ = {addSales: {show: () => {}}};
|
|
|
|
spyOn(controller, 'getClaimableFromTicket');
|
2019-06-12 06:19:02 +00:00
|
|
|
spyOn(controller.$.addSales, 'show');
|
2018-08-30 07:19:09 +00:00
|
|
|
controller.openAddSalesDialog();
|
|
|
|
|
|
|
|
expect(controller.getClaimableFromTicket).toHaveBeenCalledWith();
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.$.addSales.show).toHaveBeenCalledWith();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getClaimableFromTicket()', () => {
|
|
|
|
it('should make a query and set salesToClaim', () => {
|
|
|
|
$httpBackend.expectGET(`/api/Sales/getClaimableFromTicket?ticketFk=1`).respond(200, 1);
|
|
|
|
controller.getClaimableFromTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.salesToClaim).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-23 13:30:01 +00:00
|
|
|
describe('addClaimedSale(index)', () => {
|
2018-08-30 07:19:09 +00:00
|
|
|
it('should make a post and call refresh, hide and showSuccess', () => {
|
2019-06-12 06:19:02 +00:00
|
|
|
spyOn(controller.$.addSales, 'hide');
|
2019-04-08 07:01:10 +00:00
|
|
|
spyOn(controller.$state, 'go');
|
2018-08-30 07:19:09 +00:00
|
|
|
$httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({});
|
|
|
|
controller.addClaimedSale(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
|
2019-04-08 07:01:10 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development');
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-23 13:30:01 +00:00
|
|
|
describe('deleteClaimedSale(index)', () => {
|
2018-08-30 07:19:09 +00:00
|
|
|
it('should make a delete and call refresh and showSuccess', () => {
|
2019-06-12 06:19:02 +00:00
|
|
|
spyOn(controller.$.model, 'remove');
|
2018-08-30 07:19:09 +00:00
|
|
|
$httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({});
|
2018-11-23 13:30:01 +00:00
|
|
|
controller.deleteClaimedSale(0);
|
2018-08-30 07:19:09 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.$.model.remove).toHaveBeenCalledWith(0);
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setClaimedQuantity(id, claimedQuantity)', () => {
|
|
|
|
it('should make a patch and call refresh and showSuccess', () => {
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPATCH(`claim/api/ClaimBeginnings/`).respond({});
|
|
|
|
controller.setClaimedQuantity(1, 1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
2018-09-05 09:45:33 +00:00
|
|
|
|
|
|
|
describe('calculateTotals()', () => {
|
|
|
|
it('should set paidTotal and claimedTotal to 0 if salesClaimed has no data', () => {
|
|
|
|
controller.salesClaimed = [];
|
|
|
|
controller.calculateTotals();
|
|
|
|
|
|
|
|
expect(controller.paidTotal).toEqual(0);
|
|
|
|
expect(controller.claimedTotal).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
2019-06-12 06:19:02 +00:00
|
|
|
|
2019-06-18 05:57:41 +00:00
|
|
|
describe('updateDiscount()', () => {
|
2019-06-12 06:19:02 +00:00
|
|
|
it('should perform a query if the new discount differs from the claim discount', () => {
|
2019-06-17 10:13:05 +00:00
|
|
|
controller.saleClaimed = {sale: {
|
|
|
|
discount: 5,
|
|
|
|
id: 7,
|
|
|
|
ticketFk: 1,
|
|
|
|
price: 2,
|
|
|
|
quantity: 10}};
|
2019-06-12 06:19:02 +00:00
|
|
|
controller.newDiscount = 10;
|
2019-06-17 10:13:05 +00:00
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
spyOn(controller, 'clearDiscount');
|
|
|
|
spyOn(controller.$.model, 'refresh');
|
|
|
|
|
|
|
|
$httpBackend.when('POST', '/api/Tickets/1/updateDiscount').respond({});
|
|
|
|
controller.updateDiscount();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
expect(controller.clearDiscount).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|