Created
September 2, 2016 13:25
-
-
Save panayotkulchev/497757193d066043ce70fce3dbe95c7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Contract payment controller should", function () { | |
var ctrl, scope, gateway, deffer, growl, pageForwarding, stateParams; | |
beforeEach(function () { | |
module('bss.contract.payments'); | |
inject(function ($controller, $q, $rootScope) { | |
scope = $rootScope.$new(); | |
deffer = $q.defer(); | |
gateway = {}; | |
growl = {}; | |
pageForwarding = {}; | |
stateParams = {}; | |
ctrl = $controller("ContractPaymentsCtrl", { | |
contractBillsGateway: gateway, | |
growl: growl, | |
bssPageForwarding: pageForwarding, | |
$scope: scope, | |
$stateParams: stateParams | |
}); | |
}); | |
}); | |
it("show contract invoices", function () { | |
var contractCode = 1111; | |
pageForwarding.internal = {contractInvoices: jasmine.createSpy("contractInvoices")}; | |
ctrl.showContractInvoices(contractCode); | |
expect(pageForwarding.internal.contractInvoices).toHaveBeenCalledWith(contractCode); | |
}); | |
it("initialize page", function () { | |
gateway.getBillingPlan = jasmine.createSpy("get billing plan").and.returnValue(deffer.promise); | |
stateParams.code = "contractCode"; | |
stateParams.method = "paymentMethod"; | |
ctrl.init(); | |
expect(ctrl.contractCode).toBe("contractCode"); | |
expect(ctrl.paymentMethod).toBe("paymentMethod"); | |
expect(gateway.getBillingPlan).toHaveBeenCalledWith("contractCode"); | |
deffer.resolve({customer: "ivan", bills: [{id: "billId"}]}); | |
scope.$digest(); | |
expect(ctrl.billingPlan).toEqual({customer: "ivan", bills: [{id: "billId"}]}); | |
expect(ctrl.bills).toEqual([{id: "billId"}]); | |
}); | |
it("initialize page when contract code is missing", function () { | |
growl.warning = jasmine.createSpy("grow warning"); | |
stateParams.code = undefined; | |
ctrl.init(); | |
expect(growl.warning).toHaveBeenCalled(); | |
}); | |
it("initialize page when payment method is missing", function () { | |
growl.warning = jasmine.createSpy("grow warning"); | |
stateParams.method = undefined; | |
ctrl.init(); | |
expect(growl.warning).toHaveBeenCalled(); | |
}); | |
it("pay selected bills", function () { | |
var selectedBills = [{id: 1111}, {id: 2222}]; | |
var contractCode = "code"; | |
var paymentMethod = "CASH"; | |
var userPaymentCode = "0000"; | |
gateway.payBills = jasmine.createSpy("pay bills").and.returnValue(deffer.promise); | |
ctrl.payBills(selectedBills, contractCode, paymentMethod, userPaymentCode); | |
expect(gateway.payBills).toHaveBeenCalledWith([1111, 2222], contractCode, paymentMethod, userPaymentCode); | |
deffer.resolve([{id: 1111, payedOn: "dummy date"}, {id: 2222, payedOn: "otherDate"}]); | |
scope.$digest(); | |
expect(selectedBills).toEqual([{id: 1111, payedOn: "dummy date"}, {id: 2222, payedOn: "otherDate"}]); | |
}); | |
it("disable payment when there no bills are selected", function () { | |
var paymentCode = "paymentCode"; | |
var selectedBills = []; | |
var disabled = ctrl.paymentIsDisabled(selectedBills, paymentCode); | |
expect(disabled).toBeTruthy(); | |
}); | |
it("disable payment when paymentCode is not filled", function () { | |
var paymentCode = ""; | |
var selectedBills = [{id: 1111}]; | |
var disabled = ctrl.paymentIsDisabled(selectedBills, paymentCode); | |
expect(disabled).toBeTruthy(); | |
}); | |
it("enable payment", function () { | |
var paymentCode = "paymentCode"; | |
var selectedBills = [{id: 1111}]; | |
var disabled = ctrl.paymentIsDisabled(selectedBills, paymentCode); | |
expect(disabled).toBeFalsy(); | |
}); | |
it("show payment button", function () { | |
var selectedBills = [{id: 1111, status: 'NOT_CHARGED'}, {id: 2222, status: 'NOT_CHARGED'}]; | |
var buttonIsShown = ctrl.showPaymentBtn(selectedBills); | |
expect(buttonIsShown).toBeTruthy(); | |
}); | |
it("hide payment button", function () { | |
var selectedBills = [{id: 1111, status: 'CHARGED'}, {id: 2222, status: 'CHARGED'}]; | |
var buttonIsShown = ctrl.showPaymentBtn(selectedBills); | |
expect(buttonIsShown).toBeFalsy(); | |
}); | |
it("show payment button when no bills are selected", function () { | |
var selectedBills = []; | |
var buttonIsShown = ctrl.showPaymentBtn(selectedBills); | |
expect(buttonIsShown).toBeTruthy(); | |
}); | |
it("show reverse button", function () { | |
var selectedBills = [{id: 1111, status: 'CHARGED'}, {id: 2222, status: 'CHARGED'}]; | |
var buttonIsShown = ctrl.showReverseBtn(selectedBills); | |
expect(buttonIsShown).toBeTruthy(); | |
}); | |
it("hide reverse button", function () { | |
var selectedBills = [{id: 1111, status: 'NOT_CHARGED'}, {id: 2222, status: 'NOT_CHARGED'}]; | |
var buttonIsShown = ctrl.showReverseBtn(selectedBills); | |
expect(buttonIsShown).toBeFalsy(); | |
}); | |
it("hide reverse button when no bills are selected", function () { | |
var selectedBills = []; | |
var buttonIsShown = ctrl.showReverseBtn(selectedBills); | |
expect(buttonIsShown).toBeFalsy(); | |
}); | |
it("reverse payed bills", function () { | |
var selectedBills = [{id: 1111, status: 'CHARGED'}, {id: 2222, status: 'CHARGED'}]; | |
var contractCode = "code"; | |
var userPaymentCode = "0000"; | |
gateway.reverseBills = jasmine.createSpy("create invoice").and.returnValue(deffer.promise); | |
ctrl.reverseBills(selectedBills, contractCode, userPaymentCode); | |
expect(gateway.reverseBills).toHaveBeenCalledWith([1111, 2222], contractCode, userPaymentCode); | |
deffer.resolve([{id: 1111, status: "REVERSED"}, {id: 2222, status: "REVERSED"}]); | |
scope.$digest(); | |
expect(selectedBills).toEqual([{id: 1111, status: "REVERSED"}, {id: 2222, status: "REVERSED"}]); | |
}); | |
it("create bank invoice", function () { | |
var selectedBills = [{id: 1111}, {id: 2222}]; | |
var contractCode = "code"; | |
var userPaymentCode = "0000"; | |
gateway.createBankInvoice = jasmine.createSpy("create invoice").and.returnValue(deffer.promise); | |
ctrl.createBankInvoice(selectedBills, contractCode, userPaymentCode); | |
expect(gateway.createBankInvoice).toHaveBeenCalledWith([1111, 2222], contractCode, userPaymentCode); | |
deffer.resolve([{id: 1111, status: "INVOICED"}, {id: 2222, status: "INVOICED"}]); | |
scope.$digest(); | |
expect(selectedBills).toEqual([{id: 1111, status: "INVOICED"}, {id: 2222, status: "INVOICED"}]); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment