2020-07-01 10:53:56 +00:00
|
|
|
import './index.js';
|
2019-09-05 07:00:55 +00:00
|
|
|
import watcher from 'core/mocks/watcher';
|
2019-11-14 13:19:39 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-05-08 07:25:15 +00:00
|
|
|
|
2023-05-11 08:18:02 +00:00
|
|
|
describe('Ticket', () => {
|
2018-05-08 07:25:15 +00:00
|
|
|
describe('Component vnTicketSale', () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
let controller;
|
2018-05-08 07:25:15 +00:00
|
|
|
let $scope;
|
2019-09-13 14:09:14 +00:00
|
|
|
let $state;
|
2018-10-22 06:23:10 +00:00
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-10-22 06:23:10 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
|
2020-07-01 09:57:01 +00:00
|
|
|
const ticket = {
|
|
|
|
id: 1,
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2023-01-16 14:18:24 +00:00
|
|
|
shipped: Date.vnNew(),
|
|
|
|
landed: Date.vnNew(),
|
|
|
|
created: Date.vnNew(),
|
2020-07-01 09:57:01 +00:00
|
|
|
client: {salesPersonFk: 1},
|
|
|
|
address: {mobile: 111111111}
|
|
|
|
};
|
|
|
|
const sales = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
concept: 'Item 1',
|
|
|
|
quantity: 5,
|
|
|
|
price: 23.5,
|
|
|
|
discount: 0,
|
|
|
|
}, {
|
|
|
|
id: 4,
|
|
|
|
concept: 'Item 2',
|
|
|
|
quantity: 20,
|
|
|
|
price: 5.5,
|
|
|
|
discount: 0,
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
$state = _$state_;
|
2018-05-08 07:25:15 +00:00
|
|
|
$scope = $rootScope.$new();
|
2019-09-05 07:00:55 +00:00
|
|
|
$scope.watcher = watcher;
|
2019-09-13 14:09:14 +00:00
|
|
|
$scope.sms = {open: () => {}};
|
|
|
|
$scope.ticket = ticket;
|
2019-11-14 13:19:39 +00:00
|
|
|
$scope.model = crudModel;
|
2022-03-29 11:42:56 +00:00
|
|
|
$scope.editDiscount = {relocate: () => {}, hide: () => {}};
|
2021-08-03 09:16:43 +00:00
|
|
|
$scope.editPricePopover = {relocate: () => {}};
|
2023-04-13 11:41:10 +00:00
|
|
|
$scope.claimConfirm = {show: () => {}};
|
2018-10-22 06:23:10 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2019-09-13 14:09:14 +00:00
|
|
|
Object.defineProperties($state.params, {
|
|
|
|
id: {
|
|
|
|
value: ticket.id,
|
|
|
|
writable: true
|
|
|
|
},
|
|
|
|
go: {
|
|
|
|
value: () => {},
|
|
|
|
writable: false
|
|
|
|
}
|
|
|
|
});
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-sale></vn-ticket-sale>');
|
|
|
|
controller = $componentController('vnTicketSale', {$element, $scope});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.card = {reload: () => {}};
|
2020-07-01 09:57:01 +00:00
|
|
|
controller._ticket = ticket;
|
|
|
|
controller._sales = sales;
|
2023-04-13 11:41:10 +00:00
|
|
|
controller.ticketConfig = [
|
2023-04-13 12:04:10 +00:00
|
|
|
{daysForWarningClaim: 1}
|
2023-04-13 11:41:10 +00:00
|
|
|
];
|
|
|
|
$httpBackend.expect('GET', 'TicketConfigs').respond(200);
|
2018-05-08 07:25:15 +00:00
|
|
|
}));
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('ticket() setter', () => {
|
|
|
|
it('should set the ticket data an then call the isTicketEditable() and isTicketLocked() methods', () => {
|
|
|
|
jest.spyOn(controller, 'isTicketEditable').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'isTicketLocked').mockReturnThis();
|
2018-10-22 06:23:10 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.ticket = {id: 1};
|
2019-09-13 14:09:14 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.isTicketEditable).toHaveBeenCalledWith();
|
|
|
|
expect(controller.isTicketLocked).toHaveBeenCalledWith();
|
2018-07-13 13:57:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-19 08:24:49 +00:00
|
|
|
describe('isClaimable() getter', () => {
|
|
|
|
it('should return true for a ticket delivered less than seven days ago', () => {
|
|
|
|
const result = controller.isClaimable;
|
|
|
|
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false for a ticket delivered more than seven days ago', () => {
|
|
|
|
const ticket = controller.ticket;
|
|
|
|
const landedMinusEightDays = new Date(ticket.landed);
|
|
|
|
landedMinusEightDays.setDate(landedMinusEightDays.getDate() - 8);
|
|
|
|
ticket.landed = landedMinusEightDays;
|
|
|
|
|
|
|
|
const result = controller.isClaimable;
|
|
|
|
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('getSaleTotal()', () => {
|
|
|
|
it('should return the sale total amount', () => {
|
|
|
|
const sale = {
|
|
|
|
quantity: 10,
|
|
|
|
price: 2,
|
|
|
|
discount: 10
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedAmount = 18;
|
|
|
|
const result = controller.getSaleTotal(sale);
|
2018-05-08 07:25:15 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(result).toEqual(expectedAmount);
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('getMana()', () => {
|
|
|
|
it('should make an HTTP GET query and return the worker mana', () => {
|
|
|
|
controller.edit = {};
|
|
|
|
const expectedAmount = 250;
|
|
|
|
$httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount);
|
2022-10-21 07:08:17 +00:00
|
|
|
$httpBackend.expect('GET', 'Sales/usesMana').respond(200);
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.getMana();
|
2018-05-08 07:25:15 +00:00
|
|
|
$httpBackend.flush();
|
2020-07-01 09:57:01 +00:00
|
|
|
|
|
|
|
expect(controller.edit.mana).toEqual(expectedAmount);
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('selectedSales()', () => {
|
|
|
|
it('should return a list of selected sales', () => {
|
|
|
|
controller.sales[1].checked = true;
|
2018-07-03 13:23:10 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const expectedSaleId = 4;
|
|
|
|
const result = controller.selectedSales();
|
|
|
|
const firstSelectedSale = result[0];
|
2018-07-03 13:23:10 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(result.length).toEqual(1);
|
|
|
|
expect(firstSelectedSale.id).toEqual(expectedSaleId);
|
2018-07-03 13:23:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('selectedValidSales()', () => {
|
|
|
|
it('should return a list of selected sales having a sale id', () => {
|
|
|
|
const newEmptySale = {quantity: 10, checked: true};
|
|
|
|
controller.sales.push(newEmptySale);
|
|
|
|
controller.sales[0].checked = true;
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const expectedSaleId = 1;
|
|
|
|
const result = controller.selectedValidSales();
|
|
|
|
const firstSelectedSale = result[0];
|
2018-07-03 13:23:10 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(result.length).toEqual(1);
|
|
|
|
expect(firstSelectedSale.id).toEqual(expectedSaleId);
|
2018-05-08 07:54:14 +00:00
|
|
|
});
|
2018-07-03 13:23:10 +00:00
|
|
|
});
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('selectedSalesCount()', () => {
|
|
|
|
it('should return the number of selected sales', () => {
|
|
|
|
controller.sales[0].checked = true;
|
2018-10-22 06:23:10 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const result = controller.selectedSalesCount();
|
|
|
|
|
|
|
|
expect(result).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasSelectedSales()', () => {
|
|
|
|
it('should return truthy if atleast one sale is selected', () => {
|
|
|
|
controller.sales[0].checked = true;
|
|
|
|
|
|
|
|
const result = controller.hasSelectedSales();
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
2018-05-08 07:54:14 +00:00
|
|
|
});
|
|
|
|
});
|
2019-03-29 06:29:09 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('hasOneSaleSelected()', () => {
|
|
|
|
it('should return truthy if just one sale is selected', () => {
|
|
|
|
controller.sales[0].checked = true;
|
2019-03-29 06:29:09 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const result = controller.hasOneSaleSelected();
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return falsy if more than one sale is selected', () => {
|
2019-09-13 14:09:14 +00:00
|
|
|
controller.sales[0].checked = true;
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.sales[1].checked = true;
|
|
|
|
|
|
|
|
const result = controller.hasOneSaleSelected();
|
2019-03-29 06:29:09 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(result).toBeFalsy();
|
2019-03-29 06:29:09 +00:00
|
|
|
});
|
|
|
|
});
|
2019-07-02 10:12:15 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('newInstances()', () => {
|
|
|
|
it(`should return a list of sales that doesn't have an id`, () => {
|
|
|
|
const newEmptySale = {quantity: 10, checked: true};
|
|
|
|
controller.sales.push(newEmptySale);
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const result = controller.newInstances();
|
|
|
|
const firstNewSale = result[0];
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(result.length).toEqual(1);
|
|
|
|
expect(firstNewSale.id).toBeUndefined();
|
|
|
|
expect(firstNewSale.quantity).toEqual(10);
|
2020-03-13 07:44:01 +00:00
|
|
|
});
|
2020-07-01 09:57:01 +00:00
|
|
|
});
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('resetChanges()', () => {
|
|
|
|
it(`should not call the watcher updateOriginalData() method`, () => {
|
|
|
|
jest.spyOn(controller.$.watcher, 'updateOriginalData').mockReturnThis();
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const newEmptySale = {quantity: 10};
|
|
|
|
controller.sales.push(newEmptySale);
|
|
|
|
controller.resetChanges();
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.$.watcher.updateOriginalData).not.toHaveBeenCalledWith();
|
2020-03-13 07:44:01 +00:00
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
it(`should call the watcher updateOriginalData() method`, () => {
|
|
|
|
jest.spyOn(controller.$.watcher, 'updateOriginalData').mockReturnThis();
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.resetChanges();
|
2020-03-13 07:44:01 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
|
2020-03-13 07:44:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-13 17:48:58 +00:00
|
|
|
describe('state()', () => {
|
2023-10-27 16:03:40 +00:00
|
|
|
it('should make an HTTP post query, then call the showSuccess(),' +
|
|
|
|
' reload() and resetChanges() methods', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller.card, 'reload').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const expectedParams = {ticketFk: 1, code: 'OK'};
|
2023-10-27 16:03:40 +00:00
|
|
|
$httpBackend.expect('POST', `Tickets/state`, expectedParams).respond(200);
|
2023-09-13 17:48:58 +00:00
|
|
|
controller.state('OK');
|
2019-07-02 10:12:15 +00:00
|
|
|
$httpBackend.flush();
|
2019-09-05 07:00:55 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
2019-07-02 10:12:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('removeSales()', () => {
|
2023-10-27 16:03:40 +00:00
|
|
|
it('should make an HTTP post query, then call the showSuccess(),' +
|
|
|
|
' removeSelectedSales() and resetChanges() methods', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'removeSelectedSales').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const firstSale = controller.sales[0];
|
|
|
|
firstSale.checked = true;
|
2020-07-01 12:28:05 +00:00
|
|
|
const expectedParams = {sales: [firstSale], ticketId: 1};
|
|
|
|
$httpBackend.expect('POST', `Sales/deleteSales`, expectedParams).respond(200);
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.removeSales();
|
2019-07-02 10:12:15 +00:00
|
|
|
$httpBackend.flush();
|
2019-09-05 07:00:55 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.removeSelectedSales).toHaveBeenCalledWith();
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
2019-07-02 10:12:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('removeSelectedSales()', () => {
|
|
|
|
it('should remove the selected sales from the controller sale property', () => {
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
2019-07-02 10:12:15 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const firstSale = controller.sales[0];
|
|
|
|
firstSale.checked = true;
|
2019-07-02 10:12:15 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.removeSelectedSales();
|
2019-09-05 07:00:55 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const lastSale = controller.sales[0];
|
|
|
|
|
|
|
|
expect(controller.sales.length).toEqual(1);
|
|
|
|
expect(lastSale.id).toEqual(4);
|
2019-07-02 10:12:15 +00:00
|
|
|
});
|
|
|
|
});
|
2019-08-09 06:04:44 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('createClaim()', () => {
|
2023-04-13 12:04:10 +00:00
|
|
|
it('should call to the claimConfirm show() method', () => {
|
2023-04-13 11:41:10 +00:00
|
|
|
jest.spyOn(controller.$.claimConfirm, 'show').mockReturnThis();
|
|
|
|
|
|
|
|
controller.createClaim();
|
|
|
|
|
2023-04-13 12:04:10 +00:00
|
|
|
expect(controller.$.claimConfirm.show).toHaveBeenCalledWith();
|
2023-04-13 11:41:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onCreateClaimAccepted()', () => {
|
2023-04-13 12:04:10 +00:00
|
|
|
it('should perform a query and call window open', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
2024-08-08 06:20:26 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'getUrl').mockReturnThis();
|
|
|
|
Object.defineProperty(window, 'location', {
|
|
|
|
value: {
|
|
|
|
href: () => {}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
jest.spyOn(controller.window.location, 'href');
|
2019-08-09 06:04:44 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const newEmptySale = {quantity: 10};
|
|
|
|
controller.sales.push(newEmptySale);
|
|
|
|
const firstSale = controller.sales[0];
|
2024-08-08 06:20:26 +00:00
|
|
|
const claimId = 1;
|
2020-07-01 09:57:01 +00:00
|
|
|
firstSale.checked = true;
|
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
const expectedParams = {ticketId: 1, sales: [firstSale]};
|
2024-08-08 06:20:26 +00:00
|
|
|
$httpBackend.expect('POST', `Claims/createFromSales`, expectedParams).respond(200, {id: claimId});
|
2023-04-13 12:04:10 +00:00
|
|
|
controller.onCreateClaimAccepted();
|
2019-08-09 06:04:44 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
2019-08-09 06:04:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setTransferParams()', () => {
|
|
|
|
it('should define the transfer object on the controller and its default properties', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
const firstSale = controller.sales[0];
|
|
|
|
firstSale.checked = true;
|
|
|
|
const expectedResponse = [firstSale];
|
2019-08-09 06:04:44 +00:00
|
|
|
|
2021-06-23 11:24:23 +00:00
|
|
|
$httpBackend.expect('GET', `clients/1101/lastActiveTickets?ticketId=1`).respond(expectedResponse);
|
2019-08-09 06:04:44 +00:00
|
|
|
controller.setTransferParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
const lastActiveTickets = controller.transfer.lastActiveTickets;
|
|
|
|
|
|
|
|
expect(controller.transfer).toBeDefined();
|
|
|
|
expect(lastActiveTickets).toBeDefined();
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(lastActiveTickets[0].id).toEqual(1);
|
2019-08-09 06:04:44 +00:00
|
|
|
});
|
|
|
|
});
|
2019-09-24 12:03:30 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('transferSales()', () => {
|
|
|
|
it('should transfer sales to a ticket and then call to the $state go() method', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
|
|
|
|
|
|
|
controller.transfer = {
|
|
|
|
sales: [{id: 1, itemFk: 1}, {id: 2, itemFk: 4}]
|
|
|
|
};
|
|
|
|
|
|
|
|
const ticketIdToTransfer = 13;
|
|
|
|
const expectedResponse = {id: ticketIdToTransfer};
|
|
|
|
const params = {
|
|
|
|
ticketId: 13,
|
|
|
|
sales: controller.transfer.sales
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expect('POST', `tickets/1/transferSales`, params).respond(expectedResponse);
|
|
|
|
controller.transferSales(ticketIdToTransfer);
|
2019-09-24 12:03:30 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: ticketIdToTransfer});
|
2019-09-24 12:03:30 +00:00
|
|
|
});
|
|
|
|
});
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('updatePrice()', () => {
|
2023-10-27 16:03:40 +00:00
|
|
|
it('should make an HTTP POST query, update the sale price ' +
|
|
|
|
'and then call to the resetChanges() method', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
controller.$.editPricePopover = {hide: jest.fn()};
|
|
|
|
controller.edit = {
|
|
|
|
price: 2,
|
|
|
|
sale: selectedSale
|
|
|
|
};
|
|
|
|
const expectedParams = {newPrice: 2};
|
|
|
|
$httpBackend.expect('POST', `Sales/1/updatePrice`, expectedParams).respond(200, {price: 2});
|
|
|
|
controller.updatePrice();
|
|
|
|
$httpBackend.flush();
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(selectedSale.price).toEqual(2);
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith();
|
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
2019-11-14 13:19:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
describe('changeDiscount()', () => {
|
|
|
|
it('should call to the updateDiscount() method and then to the editDiscount hide() method', () => {
|
|
|
|
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
|
|
|
|
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
const expectedSale = selectedSale;
|
|
|
|
controller.$.editDiscount = {hide: jest.fn()};
|
|
|
|
controller.edit = {
|
|
|
|
discount: 10,
|
|
|
|
sale: selectedSale
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.changeDiscount();
|
|
|
|
|
|
|
|
expect(controller.updateDiscount).toHaveBeenCalledWith([expectedSale]);
|
|
|
|
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('changeMultipleDiscount()', () => {
|
|
|
|
it('should call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => {
|
|
|
|
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
|
|
|
|
|
|
|
|
const firstSelectedSale = controller.sales[0];
|
|
|
|
firstSelectedSale.checked = true;
|
|
|
|
|
|
|
|
const secondSelectedSale = controller.sales[1];
|
|
|
|
secondSelectedSale.checked = true;
|
|
|
|
|
|
|
|
const expectedSales = [firstSelectedSale, secondSelectedSale];
|
2022-10-14 12:38:47 +00:00
|
|
|
controller.$.editDiscount = {hide: jest.fn()};
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.edit = {
|
|
|
|
discount: 10,
|
|
|
|
sales: expectedSales
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.changeMultipleDiscount();
|
|
|
|
|
|
|
|
expect(controller.updateDiscount).toHaveBeenCalledWith(expectedSales);
|
2022-10-14 12:38:47 +00:00
|
|
|
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
2020-07-01 09:57:01 +00:00
|
|
|
});
|
|
|
|
|
2023-10-27 16:03:40 +00:00
|
|
|
it('should not call to the updateDiscount() method and then' +
|
|
|
|
' to the editDiscountDialog hide() method', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const firstSelectedSale = controller.sales[0];
|
|
|
|
firstSelectedSale.checked = true;
|
|
|
|
firstSelectedSale.discount = 10;
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2020-07-01 09:57:01 +00:00
|
|
|
const secondSelectedSale = controller.sales[1];
|
|
|
|
secondSelectedSale.checked = true;
|
|
|
|
secondSelectedSale.discount = 10;
|
|
|
|
|
|
|
|
const expectedSales = [firstSelectedSale, secondSelectedSale];
|
2022-10-14 12:38:47 +00:00
|
|
|
controller.$.editDiscount = {hide: jest.fn()};
|
2020-07-01 09:57:01 +00:00
|
|
|
controller.edit = {
|
|
|
|
discount: 10,
|
|
|
|
sales: expectedSales
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.changeMultipleDiscount();
|
|
|
|
|
|
|
|
expect(controller.updateDiscount).not.toHaveBeenCalledWith(expectedSales);
|
2022-10-14 12:38:47 +00:00
|
|
|
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
2020-07-01 09:57:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateDiscount()', () => {
|
2023-10-27 16:03:40 +00:00
|
|
|
it('should make an HTTP POST query, update the sales discount ' +
|
|
|
|
'and then call to the resetChanges() method', () => {
|
2020-07-01 09:57:01 +00:00
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
|
|
|
|
const expectedDiscount = 10;
|
|
|
|
const firstSelectedSale = controller.sales[0];
|
|
|
|
firstSelectedSale.checked = true;
|
|
|
|
|
|
|
|
const secondSelectedSale = controller.sales[1];
|
|
|
|
secondSelectedSale.checked = true;
|
|
|
|
|
|
|
|
controller.edit = {
|
|
|
|
discount: expectedDiscount
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedSales = [firstSelectedSale, secondSelectedSale];
|
|
|
|
const expectedSaleIds = [firstSelectedSale.id, secondSelectedSale.id];
|
2022-04-11 07:04:05 +00:00
|
|
|
const expectedParams = {salesIds: expectedSaleIds, newDiscount: expectedDiscount, manaCode: 'mana'};
|
2020-07-01 09:57:01 +00:00
|
|
|
$httpBackend.expect('POST', `Tickets/1/updateDiscount`, expectedParams).respond(200, {discount: 10});
|
|
|
|
controller.updateDiscount(expectedSales);
|
2019-11-14 13:19:39 +00:00
|
|
|
$httpBackend.flush();
|
2020-07-01 09:57:01 +00:00
|
|
|
|
|
|
|
expect(firstSelectedSale.discount).toEqual(expectedDiscount);
|
|
|
|
expect(secondSelectedSale.discount).toEqual(expectedDiscount);
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 09:57:01 +00:00
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
2019-11-14 13:19:39 +00:00
|
|
|
});
|
|
|
|
});
|
2020-07-01 10:53:56 +00:00
|
|
|
|
|
|
|
describe('getNewPrice()', () => {
|
|
|
|
it('should return the total price simulation from a price change', () => {
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
controller.edit = {
|
|
|
|
price: 2,
|
|
|
|
sale: selectedSale
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedAmount = 10;
|
|
|
|
const result = controller.getNewPrice();
|
|
|
|
|
|
|
|
expect(result).toEqual(expectedAmount);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the total price simulation from a discount change', () => {
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
controller.edit = {
|
|
|
|
discount: 10,
|
|
|
|
sale: selectedSale
|
|
|
|
};
|
|
|
|
|
2021-06-23 11:32:23 +00:00
|
|
|
const expectedAmount = 105.75;
|
2020-07-01 10:53:56 +00:00
|
|
|
const result = controller.getNewPrice();
|
|
|
|
|
|
|
|
expect(result).toEqual(expectedAmount);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasReserves()', () => {
|
|
|
|
it('should return true for any sale marked as reserved', () => {
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.reserved = true;
|
|
|
|
|
|
|
|
const result = controller.hasReserves();
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unmarkAsReserved()', () => {
|
|
|
|
it('should call setReserved with false', () => {
|
|
|
|
jest.spyOn(controller, 'setReserved');
|
|
|
|
|
|
|
|
controller.unmarkAsReserved(false);
|
|
|
|
|
|
|
|
expect(controller.setReserved).toHaveBeenCalledWith(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('markAsReserved()', () => {
|
|
|
|
it('should call setReserved with true', () => {
|
|
|
|
jest.spyOn(controller, 'setReserved');
|
|
|
|
|
|
|
|
controller.markAsReserved(true);
|
|
|
|
|
|
|
|
expect(controller.setReserved).toHaveBeenCalledWith(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setReserved()', () => {
|
|
|
|
it('should call getCheckedLines, $.index.accept and make a query ', () => {
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
const expectedParams = {
|
|
|
|
sales: [selectedSale],
|
2020-07-01 12:28:05 +00:00
|
|
|
ticketId: 1,
|
2020-07-01 10:53:56 +00:00
|
|
|
reserved: false
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Sales/reserve`, expectedParams).respond();
|
|
|
|
controller.unmarkAsReserved(false);
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('newOrderFromTicket()', () => {
|
|
|
|
it('should make an HTTP post query and then open the new order on a new tab', () => {
|
|
|
|
const expectedParams = {ticketFk: 1};
|
|
|
|
const expectedResponse = {id: 123};
|
|
|
|
|
|
|
|
window.open = jasmine.createSpy('open');
|
|
|
|
|
|
|
|
$httpBackend.expect('POST', `Orders/newFromTicket`, expectedParams).respond(expectedResponse);
|
|
|
|
controller.newOrderFromTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showSMSDialog()', () => {
|
|
|
|
it('should open an SMS dialog with specified data', () => {
|
|
|
|
jest.spyOn(controller.$.sms, 'open');
|
|
|
|
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
controller.showSMSDialog();
|
|
|
|
|
|
|
|
expect(controller.$.sms.open).toHaveBeenCalledWith();
|
|
|
|
expect(controller.newSMS.destination).toEqual(111111111);
|
|
|
|
expect(controller.newSMS.message).not.toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('changeQuantity()', () => {
|
|
|
|
it('should not call addSale() or updateQuantity() methods', () => {
|
|
|
|
jest.spyOn(controller, 'addSale');
|
|
|
|
jest.spyOn(controller, 'updateQuantity');
|
|
|
|
|
|
|
|
const sale = {itemFk: 4};
|
|
|
|
controller.changeQuantity(sale);
|
|
|
|
|
|
|
|
expect(controller.addSale).not.toHaveBeenCalled();
|
|
|
|
expect(controller.updateQuantity).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call addSale() method', () => {
|
|
|
|
jest.spyOn(controller, 'addSale');
|
|
|
|
|
|
|
|
const sale = {itemFk: 4, quantity: 5};
|
|
|
|
controller.changeQuantity(sale);
|
|
|
|
|
|
|
|
expect(controller.addSale).toHaveBeenCalledWith(sale);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call updateQuantity() method', () => {
|
|
|
|
jest.spyOn(controller, 'addSale');
|
|
|
|
jest.spyOn(controller, 'updateQuantity');
|
|
|
|
|
|
|
|
const sale = {id: 1, itemFk: 4, quantity: 5};
|
|
|
|
controller.changeQuantity(sale);
|
|
|
|
|
|
|
|
expect(controller.addSale).not.toHaveBeenCalled();
|
|
|
|
expect(controller.updateQuantity).toHaveBeenCalledWith(sale);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateQuantity()', () => {
|
|
|
|
it('should make a POST query saving sale quantity', () => {
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
selectedSale.quantity = 10;
|
|
|
|
|
|
|
|
const expectedParams = {quantity: 10};
|
|
|
|
$httpBackend.expect('POST', `Sales/1/updateQuantity`, expectedParams).respond();
|
|
|
|
controller.updateQuantity(selectedSale);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateConcept()', () => {
|
|
|
|
it('should make a POST query saving sale concept', () => {
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const selectedSale = controller.sales[0];
|
|
|
|
selectedSale.checked = true;
|
|
|
|
selectedSale.concept = 'My new weapon';
|
|
|
|
|
|
|
|
const expectedParams = {newConcept: 'My new weapon'};
|
|
|
|
$httpBackend.expect('POST', `Sales/1/updateConcept`, expectedParams).respond();
|
|
|
|
controller.updateConcept(selectedSale);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addSale()', () => {
|
|
|
|
it('should make a POST query adding a new sale', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
|
|
|
|
|
|
|
const newSale = {itemFk: 4, quantity: 10};
|
2024-05-17 12:20:33 +00:00
|
|
|
const expectedParams = {barcode: 4, quantity: 10};
|
2020-07-01 10:53:56 +00:00
|
|
|
const expectedResult = {
|
|
|
|
id: 30,
|
|
|
|
quantity: 10,
|
|
|
|
discount: 0,
|
|
|
|
price: 0,
|
|
|
|
itemFk: 4,
|
|
|
|
item: {
|
|
|
|
subName: 'Item subName',
|
|
|
|
image: '30.png'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expect('POST', `tickets/1/addSale`, expectedParams).respond(expectedResult);
|
|
|
|
controller.addSale(newSale);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 10:53:56 +00:00
|
|
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isTicketEditable()', () => {
|
|
|
|
it('should make a HTTP GET query and set the isEditable property on the controller', () => {
|
|
|
|
$httpBackend.expect('GET', `Tickets/1/isEditable`).respond(200, true);
|
|
|
|
controller.isTicketEditable();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.isEditable).toBeDefined();
|
|
|
|
expect(controller.isEditable).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isTicketLocked()', () => {
|
|
|
|
it('should make a HTTP GET query and set the isLocked property on the controller', () => {
|
|
|
|
$httpBackend.expect('GET', `Tickets/1/isLocked`).respond(200, false);
|
|
|
|
controller.isTicketLocked();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.isLocked).toBeDefined();
|
|
|
|
expect(controller.isLocked).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('calculateSalePrice()', () => {
|
2021-12-01 10:39:48 +00:00
|
|
|
it('should make an HTTP post query', () => {
|
2020-07-01 10:53:56 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
|
|
|
|
|
2021-12-01 10:39:48 +00:00
|
|
|
controller.sales.forEach(sale => {
|
|
|
|
sale.checked = true;
|
|
|
|
});
|
2020-07-01 10:53:56 +00:00
|
|
|
|
2021-11-30 12:47:16 +00:00
|
|
|
$httpBackend.expect('POST', `Sales/recalculatePrice`).respond(200);
|
2020-07-01 10:53:56 +00:00
|
|
|
controller.calculateSalePrice();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2020-07-01 10:53:56 +00:00
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2021-09-03 12:00:47 +00:00
|
|
|
|
2022-04-04 11:26:53 +00:00
|
|
|
describe('createRefund()', () => {
|
2022-07-14 11:40:50 +00:00
|
|
|
it('should make a query and then navigate to the created ticket sales section', () => {
|
2021-12-21 13:43:53 +00:00
|
|
|
jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales);
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
2022-07-14 11:40:50 +00:00
|
|
|
const params = {
|
|
|
|
salesIds: [1, 4],
|
2024-01-31 08:59:32 +00:00
|
|
|
negative: true
|
2022-07-14 11:40:50 +00:00
|
|
|
};
|
|
|
|
const refundTicket = {id: 99};
|
2024-01-26 14:32:50 +00:00
|
|
|
$httpBackend.expect('POST', 'Sales/clone', params).respond(200, [refundTicket]);
|
2022-04-04 11:26:53 +00:00
|
|
|
controller.createRefund();
|
2021-12-15 14:24:45 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2022-07-14 11:40:50 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', refundTicket);
|
2021-12-15 14:24:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-03 12:00:47 +00:00
|
|
|
describe('itemSearchFunc()', () => {
|
|
|
|
it('should return the filter by id property for an input of a number', () => {
|
|
|
|
const itemId = 1;
|
|
|
|
const result = controller.itemSearchFunc(itemId);
|
|
|
|
|
|
|
|
expect(result).toEqual({id: itemId});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the filter by bank property for an input of an string', () => {
|
|
|
|
const itemName = 'Bow';
|
|
|
|
const result = controller.itemSearchFunc(itemName);
|
|
|
|
|
|
|
|
expect(result).toEqual({name: {like: '%' + itemName + '%'}});
|
|
|
|
});
|
|
|
|
});
|
2022-03-29 11:42:56 +00:00
|
|
|
|
|
|
|
describe('cancel()', () => {
|
|
|
|
it('should call hide()', () => {
|
|
|
|
jest.spyOn(controller.$.editDiscount, 'hide').mockReturnThis();
|
|
|
|
controller.cancel();
|
|
|
|
|
|
|
|
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2023-05-11 08:17:41 +00:00
|
|
|
|
|
|
|
describe('sortBy()', () => {
|
|
|
|
it('should set reverse and propertyName properties', () => {
|
|
|
|
const propertyName = 'id';
|
|
|
|
controller.sortBy(propertyName);
|
|
|
|
|
|
|
|
expect(controller.propertyName).toEqual(propertyName);
|
|
|
|
expect(controller.reverse).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|