|
1 | 1 | /* jshint -W117, -W030 */ |
2 | | -(function () { |
| 2 | +(function() { |
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | | - describe('Service: userService', function () { |
| 5 | + describe('Service: userService', function() { |
6 | 6 |
|
7 | 7 | var service; |
8 | 8 | var _user = { |
|
13 | 13 | }; |
14 | 14 |
|
15 | 15 | beforeEach(function() { |
16 | | - bard.appModule('app.user', 'app'); |
| 16 | + bard.appModule('app.user'); |
17 | 17 | bard.inject('$q', '$http', '$rootScope', '$state', 'loginService'); |
18 | 18 |
|
19 | 19 | bard.mockService($http, { |
|
39 | 39 |
|
40 | 40 | }); |
41 | 41 |
|
42 | | - beforeEach(inject(function (_userService_) { |
| 42 | + beforeEach(inject(function(_userService_) { |
43 | 43 | service = _userService_; |
44 | 44 | })); |
45 | 45 |
|
46 | | - it('should be defined', function () { |
| 46 | + it('should be defined', function() { |
47 | 47 | expect(service).to.be.defined; |
48 | 48 | }); |
49 | 49 |
|
50 | | - it('currentUser should not be defined', function () { |
| 50 | + it('currentUser should not be defined', function() { |
51 | 51 | expect(service.currentUser()).to.not.be.defined; |
52 | 52 | }); |
53 | 53 |
|
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() { |
55 | 55 | service.getUser().then(function(user) { |
56 | 56 | expect(user).to.deep.eq(null); |
57 | 57 | }); |
|
61 | 61 | $rootScope.$apply(); |
62 | 62 | }); |
63 | 63 |
|
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 | + }); |
112 | 86 | }); |
113 | 87 | }()); |
0 commit comments