@@ -3,7 +3,7 @@ const mockData = require('../../../tests/test-helpers/mock-data')
3
3
4
4
/* jshint -W117, -W030 */
5
5
describe ( 'Header Dashboard Controller' , function ( ) {
6
- var identity
6
+ var userService , profileService , identity
7
7
var profile = mockData . getMockProfile ( )
8
8
var stats = mockData . getMockStats ( )
9
9
var financials = mockData . getMockUserFinancials ( )
@@ -14,14 +14,45 @@ describe('Header Dashboard Controller', function() {
14
14
'$controller' ,
15
15
'$rootScope' ,
16
16
'$q' ,
17
+ 'UserService' ,
18
+ 'ProfileService' ,
17
19
'Helpers' )
18
20
21
+ userService = UserService
22
+ profileService = ProfileService
23
+
19
24
identity = function ( ) {
20
25
return {
21
26
handle : 'albertwang' ,
22
27
userId : 123456
23
28
}
24
29
}
30
+
31
+ // mock user api
32
+ sinon . stub ( userService , 'getUserIdentity' , function ( ) {
33
+ return {
34
+ userId : 1234567 ,
35
+ handle : 'ut' ,
36
+
37
+ }
38
+ } )
39
+
40
+ // mock profile api
41
+ sinon . stub ( profileService , 'getUserProfile' , function ( handle ) {
42
+ var deferred = $q . defer ( )
43
+ deferred . resolve ( profile )
44
+ return deferred . promise
45
+ } )
46
+ sinon . stub ( profileService , 'getUserStats' , function ( handle ) {
47
+ var deferred = $q . defer ( )
48
+ deferred . resolve ( stats )
49
+ return deferred . promise
50
+ } )
51
+ sinon . stub ( profileService , 'getUserFinancials' , function ( handle ) {
52
+ var deferred = $q . defer ( )
53
+ deferred . resolve ( financials )
54
+ return deferred . promise
55
+ } )
25
56
} )
26
57
27
58
bard . verifyNoOutstandingHttpRequests ( )
@@ -30,6 +61,9 @@ describe('Header Dashboard Controller', function() {
30
61
var controller = null
31
62
beforeEach ( function ( ) {
32
63
controller = $controller ( 'HeaderDashboardController' , {
64
+ UserService : userService ,
65
+ ProfileService : profileService ,
66
+ userIdentity : identity ,
33
67
profile : profile
34
68
} )
35
69
$rootScope . $apply ( )
@@ -41,17 +75,51 @@ describe('Header Dashboard Controller', function() {
41
75
} )
42
76
} )
43
77
44
- describe ( 'inialization with null profile' , function ( ) {
78
+ describe ( 'inialization with profile api stats endpoint error ' , function ( ) {
45
79
var controller = null
46
80
beforeEach ( function ( ) {
81
+ profileService . getUserStats . restore ( )
82
+ sinon . stub ( profileService , 'getUserStats' , function ( handle ) {
83
+ var deferred = $q . defer ( )
84
+ deferred . reject ( 'failed' )
85
+ return deferred . promise
86
+ } )
87
+ controller = $controller ( 'HeaderDashboardController' , {
88
+ UserService : userService ,
89
+ ProfileService : profileService ,
90
+ userIdentity : identity ,
91
+ profile : profile
92
+ } )
93
+ $rootScope . $apply ( )
94
+ } )
95
+
96
+ it ( 'variables should be initialized to correct value' , function ( ) {
97
+ expect ( controller . profile ) . to . exist
98
+ expect ( controller . profile . handle ) . to . equal ( 'albertwang' )
99
+ } )
100
+ } )
101
+
102
+ describe ( 'inialization with profile api profile endpoint error' , function ( ) {
103
+ var controller = null
104
+ beforeEach ( function ( ) {
105
+ profileService . getUserProfile . restore ( )
106
+ sinon . stub ( profileService , 'getUserProfile' , function ( handle ) {
107
+ var deferred = $q . defer ( )
108
+ deferred . reject ( 'failed' )
109
+ return deferred . promise
110
+ } )
47
111
controller = $controller ( 'HeaderDashboardController' , {
48
- profile : null
112
+ UserService : userService ,
113
+ ProfileService : profileService ,
114
+ userIdentity : identity ,
115
+ profile : profileService . getUserProfile ( )
49
116
} )
50
117
$rootScope . $apply ( )
51
118
} )
52
119
53
120
it ( 'variables should be initialized to correct value' , function ( ) {
54
- expect ( controller . profile ) . to . be . null
121
+ expect ( controller . profile . $$state . status ) . to . equal ( 2 )
122
+ expect ( controller . profile . $$state . value ) . to . equal ( 'failed' )
55
123
} )
56
124
} )
57
125
0 commit comments