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

723 lines
28 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';
2020-03-13 07:47:41 +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
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
2020-07-01 09:57:01 +00:00
const ticket = {
id: 1,
clientFk: 101,
shipped: 1,
created: new Date(),
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;
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;
}));
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
});
});
2020-07-01 09:57:01 +00:00
describe('sales() setter', () => {
it('should set the sales data an then call the refreshTotal() method', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
2020-07-01 09:57:01 +00:00
controller.sales = [{id: 1}];
expect(controller.refreshTotal).toHaveBeenCalledWith();
});
});
2020-07-01 09:57:01 +00:00
describe('getSubTotal()', () => {
it('should make an HTTP GET query and then set the subtotal property', () => {
const expectedAmount = 128;
$httpBackend.expect('GET', 'Tickets/1/subtotal').respond(200, expectedAmount);
controller.getSubTotal();
2019-09-13 14:09:14 +00:00
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.subtotal).toEqual(expectedAmount);
2018-07-13 13:57:19 +00:00
});
});
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);
controller.getMana();
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.edit.mana).toEqual(expectedAmount);
});
});
2020-07-01 09:57:01 +00:00
describe('getVat()', () => {
it('should make an HTTP GET query and return the ticket VAT', () => {
controller.edit = {};
const expectedAmount = 67;
2018-07-03 13:23:10 +00:00
2020-07-01 09:57:01 +00:00
$httpBackend.expect('GET', 'Tickets/1/getVAT').respond(200, expectedAmount);
controller.getVat();
2018-07-03 13:23:10 +00:00
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.VAT).toEqual(expectedAmount);
2018-07-03 13:23:10 +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;
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).toHaveBeenCalledWith('Data saved!');
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], actualTicketFk: 1};
$httpBackend.expect('POST', `Sales/removes`, expectedParams).respond(200);
controller.removeSales();
$httpBackend.flush();
2020-07-01 09:57:01 +00:00
expect(controller.removeSelectedSales).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
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, 'refreshTotal').mockReturnThis();
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);
expect(controller.refreshTotal).toHaveBeenCalledWith();
});
});
2019-08-09 06:04:44 +00:00
2020-07-01 09:57:01 +00:00
describe('createClaim()', () => {
it('should perform a query and call windows open', () => {
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 = {
claim: {ticketFk: 1, clientFk: 101, ticketCreated: 1},
sales: [firstSale]
2019-08-09 06:04:44 +00:00
};
2020-07-01 09:57:01 +00:00
$httpBackend.expect('POST', `Claims/createFromSales`, expectedParams).respond(200, {id: 1});
controller.createClaim();
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/101/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).toHaveBeenCalledWith('Data saved!');
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];
controller.$.editDiscountDialog = {hide: jest.fn()};
controller.edit = {
discount: 10,
sales: expectedSales
};
controller.changeMultipleDiscount();
expect(controller.updateDiscount).toHaveBeenCalledWith(expectedSales);
expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith();
});
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];
controller.$.editDiscountDialog = {hide: jest.fn()};
controller.edit = {
discount: 10,
sales: expectedSales
};
controller.changeMultipleDiscount();
expect(controller.updateDiscount).not.toHaveBeenCalledWith(expectedSales);
expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith();
});
});
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];
const expectedParams = {salesIds: expectedSaleIds, newDiscount: expectedDiscount};
$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).toHaveBeenCalledWith('Data saved!');
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
};
const expectedAmount = 105.75;
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],
ticketFk: 1,
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).toHaveBeenCalledWith('Data saved!');
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()', () => {
it('should make an HTTP post query ', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
const selectedSale = controller.sales[0];
selectedSale.checked = true;
$httpBackend.expect('POST', `Sales/1/recalculatePrice`).respond(200);
controller.calculateSalePrice();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
});
});