Skip to content

Commit

Permalink
Removing testing code left in last commit. Implementing unit tests fo…
Browse files Browse the repository at this point in the history
…r password reset section of userService.
  • Loading branch information
Jeremy Sik committed Jul 29, 2015
1 parent 9c9ee09 commit f7f6a23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/app/guest/login/resetPassword.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('ResetPassword', () => {

});

describe.only('dialog interactions - reset password', () => {
describe('dialog interactions - reset password', () => {

it('should cancel dialog when requested', () => {

Expand Down
28 changes: 26 additions & 2 deletions app/src/common/services/userService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@
let $httpBackend:ng.IHttpBackendService;
let authService:NgJwtAuth.NgJwtAuthService;
let ngRestAdapter:NgRestAdapter.NgRestAdapterService;
let $mdDialog:ng.material.IDialogService;
let $timeout:ng.ITimeoutService;

beforeEach(()=> {

module('app');

inject((_$httpBackend_, _userService_, _ngJwtAuthService_, _ngRestAdapter_) => {
inject((_$httpBackend_, _userService_, _ngJwtAuthService_, _ngRestAdapter_, _$mdDialog_, _$timeout_) => {

if (!userService) { //dont rebind, so each test gets the singleton
$httpBackend = _$httpBackend_;
userService = _userService_;
authService = _ngJwtAuthService_;
ngRestAdapter = _ngRestAdapter_;
$mdDialog = _$mdDialog_;
$timeout = _$timeout_;
}
});

Expand Down Expand Up @@ -156,9 +160,29 @@

it('should open the password reset dialog', () => {

sinon.spy($mdDialog, 'show');

userService.promptResetPassword();

$timeout.flush();

expect($mdDialog.show).to.have.been.called;

(<any>$mdDialog).show.restore();

});

it('should do something', () => {
it('should be able to send a reset password email', () => {

let email = 'test@email.com';

$httpBackend.expectDELETE('/api/users/' + email + '/password').respond(202);

let resetPasswordPromise = userService.resetPassword(email);

expect(resetPasswordPromise).eventually.to.be.fulfilled;

$httpBackend.flush();

});

Expand Down

0 comments on commit f7f6a23

Please sign in to comment.