Skip to content

Instantly share code, notes, and snippets.

@johnykov
Last active January 18, 2018 08:43
Show Gist options
  • Save johnykov/ac99f1aea9b7fd5d7088acadd9eb7e6a to your computer and use it in GitHub Desktop.
Save johnykov/ac99f1aea9b7fd5d7088acadd9eb7e6a to your computer and use it in GitHub Desktop.
mocha, chai, sinon
describe('should navigate repeated customer ', () => {
let scope, ctrl, state, rootScope, fakeProfileService, sandbox, $provide, $controller;
beforeEach(module('rootApp'));
afterEach(() => sandbox.restore());
beforeEach(() => module('rootApp', function(_$provide_) {
$provide = _$provide_;
}));
beforeEach(() => inject(function($rootScope, _$controller_, $state, ProfileService) {
$controller = _$controller_;
scope = $rootScope.$new();
rootScope = $rootScope;
state = $state;
sandbox = sinon.sandbox.create();
fakeProfileService = ProfileService;
state.transitionTo = sandbox.stub();
fakeProfileService.createNewApplication = sandbox.stub();
fakeProfileService.preevaluateApplication = sandbox.stub();
rootScope.enablePositiveCounterOffer = true;
}));
it('and enable overlay after applyAndConfirm', inject(function($timeout) {
provideProfileData();
injectCtrl();
const CREDIT_LIMIT = 600, ASKED_AMOUNT = 500;
fakeProfileService.createNewApplication.returns({
success: (callback) => callback({amount: ASKED_AMOUNT})
}
);
fakeProfileService.preevaluateApplication.returns({
success: (callback) => callback({creditLimit: CREDIT_LIMIT})
}
);
//given
expect(rootScope.overlayEnabled).to.be.undefined;
expect(scope.confirmData).to.have.any.keys('agreeWithTerms', 'agreeWithbigCheck');
//when
scope.applyAndConfirm();
$timeout.flush();
// then
expect(rootScope.overlayEnabled).to.be.true;
expect(fakeProfileService.createNewApplication).to.be.calledOnce
expect(fakeProfileService.preevaluateApplication).to.be.calledOnce
}));
function injectCtrl() {
ctrl = $controller('ProfileConfirmApplicationCtrl', {
$scope: scope,
$rootScope: rootScope,
$stateParams: {loanApplication: {}, offer: {}, applicationIsNew: true},
profileService: fakeProfileService,
$state: state
});
}
function provideProfileData(fakeProfileData = {
client: {canApplyForLoan: true, paidLoanCount: 1},
consents: {data: []}
}) {
$provide.value('ProfileData', fakeProfileData);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment