salix/modules/ticket/front/sale/index.spec.js

763 lines
30 KiB
JavaScript
Raw Normal View History

2020-07-01 10:53:56 +00:00
import './index.js';
import watcher from 'core/mocks/watcher';
import crudModel from 'core/mocks/crud-model';
2021-12-21 14:00:06 +00:00
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
2018-11-06 13:27:16 +00:00
let controller;
let $scope;
2019-09-13 14:09:14 +00:00
let $state;
2018-10-22 06:23:10 +00:00
let $httpBackend;
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,
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_;
$scope = $rootScope.$new();
$scope.watcher = watcher;
2019-09-13 14:09:14 +00:00
$scope.sms = {open: () => {}};
$scope.ticket = ticket;
$scope.model = crudModel;
2022-03-29 11:42:56 +00:00
$scope.editDiscount = {relocate: () => {}, hide: () => {}};
$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);
}));
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);
2020-07-01 09:57:01 +00:00
expect(result).toEqual(expectedAmount);
});
});
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);
$httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount);
2020-07-01 09:57:01 +00:00
controller.getMana();
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.edit.mana).toEqual(expectedAmount);
expect(controller.currentWorkerMana).toEqual(expectedAmount);
});
});
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;
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-07-03 13:23:10 +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();
});
});
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;
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();
2020-07-01 09:57:01 +00:00
expect(result).toBeFalsy();
});
});
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
});
});
2020-07-01 09:57:01 +00:00
describe('changeState()', () => {
it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => {
jest.spyOn(controller.card, 'reload').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis();
const expectedParams = {ticketFk: 1, code: 'OK'};
$httpBackend.expect('POST', `TicketTrackings/changeState`, expectedParams).respond(200);
controller.changeState('OK');
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2020-07-01 09:57:01 +00:00
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
2020-07-01 09:57:01 +00:00
describe('removeSales()', () => {
it('should make an HTTP post query, then call the showSuccess(), removeSelectedSales() and resetChanges() methods', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'removeSelectedSales').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis();
const firstSale = controller.sales[0];
firstSale.checked = true;
const expectedParams = {sales: [firstSale], ticketId: 1};
$httpBackend.expect('POST', `Sales/deleteSales`, expectedParams).respond(200);
2020-07-01 09:57:01 +00:00
controller.removeSales();
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.removeSelectedSales).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2020-07-01 09:57:01 +00:00
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
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();
2020-07-01 09:57:01 +00:00
const firstSale = controller.sales[0];
firstSale.checked = true;
2020-07-01 09:57:01 +00:00
controller.removeSelectedSales();
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-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();
jest.spyOn(controller.$state, 'go').mockReturnThis();
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];
firstSale.checked = true;
const expectedParams = {ticketId: 1, sales: [firstSale]};
2020-07-01 09:57:01 +00:00
$httpBackend.expect('POST', `Claims/createFromSales`, expectedParams).respond(200, {id: 1});
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();
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.basicData', {id: 1});
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
$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
});
});
2020-07-01 09:57:01 +00:00
describe('updatePrice()', () => {
it('should make an HTTP POST query, update the sale price and then call to the resetChanges() method', () => {
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();
2020-07-01 09:57:01 +00:00
expect(selectedSale.price).toEqual(2);
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2020-07-01 09:57:01 +00:00
expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
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
});
it('should not call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => {
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
2020-07-01 09:57:01 +00:00
const firstSelectedSale = controller.sales[0];
firstSelectedSale.checked = true;
firstSelectedSale.discount = 10;
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()', () => {
it('should make an HTTP POST query, update the sales discount and then call to the resetChanges() method', () => {
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);
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(firstSelectedSale.discount).toEqual(expectedDiscount);
expect(secondSelectedSale.discount).toEqual(expectedDiscount);
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2020-07-01 09:57:01 +00:00
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
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],
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');
controller.$state.href = jasmine.createSpy('href')
.and.returnValue('/somePath');
$httpBackend.expect('POST', `Orders/newFromTicket`, expectedParams).respond(expectedResponse);
controller.newOrderFromTicket();
$httpBackend.flush();
expect(window.open).toHaveBeenCalledWith('/somePath', '_blank');
});
});
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};
const expectedParams = {itemId: 4, quantity: 10};
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();
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();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2020-07-01 10:53:56 +00:00
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
describe('createRefund()', () => {
it('should make a query and then navigate to the created ticket sales section', () => {
jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales);
jest.spyOn(controller.$state, 'go');
const params = {
salesIds: [1, 4],
};
const refundTicket = {id: 99};
2023-04-24 06:57:10 +00:00
$httpBackend.expect('POST', 'Sales/refund', params).respond(200, refundTicket);
controller.createRefund();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', refundTicket);
});
});
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();
});
});
});
});