Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 68ffa66

Browse files
committed
fixing dependencies and the user service unit tests
1 parent d09dcd7 commit 68ffa66

File tree

5 files changed

+33
-59
lines changed

5 files changed

+33
-59
lines changed

app/templates/ui/app/create/create.controller.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var nextState;
99

1010
beforeEach(function() {
11-
bard.appModule('app.create', 'ngToast');
11+
bard.appModule('app.create');
1212
bard.inject('$controller', '$q', '$rootScope', 'MLRest', '$state', 'userService');
1313

1414
bard.mockService(MLRest, {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
22
'use strict';
33

4-
angular.module('app.create', ['ml.common', 'app.user']);
4+
angular.module('app.create', ['ml.common', 'app.user', 'ngToast']);
55
}());

app/templates/ui/app/user/profile.controller.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
var currentState;
1414

1515
beforeEach(function() {
16-
bard.appModule('app.user', 'ngToast');
16+
bard.appModule('app.user');
1717
bard.inject('$controller', '$q', '$rootScope', 'MLRest', '$state', 'userService');
1818

1919
bard.mockService(MLRest, {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
22
'use strict';
33

4-
angular.module('app.user', ['ml.common', 'app.login']);
4+
angular.module('app.user', ['ml.common', 'app.login', 'ngToast']);
55
}());
Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* jshint -W117, -W030 */
2-
(function () {
2+
(function() {
33
'use strict';
44

5-
describe('Service: userService', function () {
5+
describe('Service: userService', function() {
66

77
var service;
88
var _user = {
@@ -13,7 +13,7 @@
1313
};
1414

1515
beforeEach(function() {
16-
bard.appModule('app.user', 'app');
16+
bard.appModule('app.user');
1717
bard.inject('$q', '$http', '$rootScope', '$state', 'loginService');
1818

1919
bard.mockService($http, {
@@ -39,19 +39,19 @@
3939

4040
});
4141

42-
beforeEach(inject(function (_userService_) {
42+
beforeEach(inject(function(_userService_) {
4343
service = _userService_;
4444
}));
4545

46-
it('should be defined', function () {
46+
it('should be defined', function() {
4747
expect(service).to.be.defined;
4848
});
4949

50-
it('currentUser should not be defined', function () {
50+
it('currentUser should not be defined', function() {
5151
expect(service.currentUser()).to.not.be.defined;
5252
});
5353

54-
it('should get the current logged in user - if loginService not init', function () {
54+
it('should get the current logged in user - if loginService not init', function() {
5555
service.getUser().then(function(user) {
5656
expect(user).to.deep.eq(null);
5757
});
@@ -61,53 +61,27 @@
6161
$rootScope.$apply();
6262
});
6363

64-
// it('should login correctly using loginService', function () {
65-
// $rootScope.$broadcast('loginService:login-success', _user);
66-
// $rootScope.$digest(service);
67-
68-
// service.getUser().then(function(user) {
69-
// expect(user).to.deep.eq('bob');
70-
// });
71-
72-
// expect(service.updateUser).to.have.been.calledOnce;
73-
74-
// $rootScope.$apply();
75-
// });
76-
77-
// it('should set user with valid credentials', function () {
78-
// loginService.login('test', 'abc').then(function(response) {
79-
// expect(response.data).to.deep.eq({ authenticated: true, username: 'bob' });
80-
// expect(service.currentUser()).to.deep.eq({ name: 'bob' });
81-
// expect(service.getUser()).to.deep.eq({ name: 'bob' });
82-
// });
83-
// expect($http.post).to.have.been.calledOnce;
84-
// $rootScope.$apply();
85-
// });
86-
87-
// it('should not set user with invalid credentials', function () {
88-
// _user.data.authenticated = false;
89-
// loginService.login('test', 'abcd').then(function(response) {
90-
// expect(response.data.authenticated).to.be.false;
91-
// expect(service.currentUser()).to.not.be.defined;
92-
// });
93-
// expect($http.post).to.have.been.calledOnce;
94-
// $rootScope.$apply();
95-
// });
96-
97-
// it('should clear user after logout', function () {
98-
// expect(service.currentUser()).to.not.be.defined;
99-
// _user.data.authenticated = true;
100-
// loginService.login('test', 'abcd').then(function(response) {
101-
// expect(response.data).to.deep.eq({ authenticated: true, username: 'bob' });
102-
// expect(service.currentUser()).to.deep.eq({ name: 'bob' });
103-
104-
// loginService.logout().then(function(response) {
105-
// expect(loginService.isAuthenticated()).to.be.false;
106-
// expect(service.currentUser()).to.not.be.defined;
107-
// });
108-
// });
109-
110-
// $rootScope.$apply();
111-
// });
64+
it('should update the current user when logged in using loginService', function(done) {
65+
$rootScope.$broadcast('loginService:login-success', {data:_user});
66+
$rootScope.$apply(service);
67+
68+
done();
69+
expect(service.currentUser().name).to.eq('bob');
70+
});
71+
72+
it('should not set user with invalid credentials', function () {
73+
_user.data.authenticated = false;
74+
$rootScope.$broadcast('loginService:login-success', {data:_user});
75+
$rootScope.$apply(service);
76+
77+
expect(service.currentUser().name).to.eq(undefined);
78+
});
79+
80+
it('should clear user after logout', function () {
81+
$rootScope.$broadcast('loginService:logout-success');
82+
$rootScope.$apply(service);
83+
84+
expect(service.currentUser()).to.not.be.defined;
85+
});
11286
});
11387
}());

0 commit comments

Comments
 (0)