Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e58636f

Browse files
committed
Revert "Github issue #919, Few Unit tests failing after angular 1.6.x release"
This reverts commit 2d4c680.
1 parent 5764ed3 commit e58636f

File tree

3 files changed

+239
-178
lines changed

3 files changed

+239
-178
lines changed

app/my-dashboard/header-dashboard/header-dashboard.spec.js

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const mockData = require('../../../tests/test-helpers/mock-data')
33

44
/* jshint -W117, -W030 */
55
describe('Header Dashboard Controller', function() {
6-
var identity
6+
var userService, profileService, identity
77
var profile = mockData.getMockProfile()
88
var stats = mockData.getMockStats()
99
var financials = mockData.getMockUserFinancials()
@@ -14,14 +14,45 @@ describe('Header Dashboard Controller', function() {
1414
'$controller',
1515
'$rootScope',
1616
'$q',
17+
'UserService',
18+
'ProfileService',
1719
'Helpers')
1820

21+
userService = UserService
22+
profileService = ProfileService
23+
1924
identity = function() {
2025
return {
2126
handle: 'albertwang',
2227
userId: 123456
2328
}
2429
}
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+
})
2556
})
2657

2758
bard.verifyNoOutstandingHttpRequests()
@@ -30,6 +61,9 @@ describe('Header Dashboard Controller', function() {
3061
var controller = null
3162
beforeEach( function(){
3263
controller = $controller('HeaderDashboardController', {
64+
UserService : userService,
65+
ProfileService: profileService,
66+
userIdentity: identity,
3367
profile: profile
3468
})
3569
$rootScope.$apply()
@@ -41,17 +75,51 @@ describe('Header Dashboard Controller', function() {
4175
})
4276
})
4377

44-
describe('inialization with null profile', function() {
78+
describe('inialization with profile api stats endpoint error', function() {
4579
var controller = null
4680
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+
})
47111
controller = $controller('HeaderDashboardController', {
48-
profile: null
112+
UserService : userService,
113+
ProfileService: profileService,
114+
userIdentity: identity,
115+
profile: profileService.getUserProfile()
49116
})
50117
$rootScope.$apply()
51118
})
52119

53120
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')
55123
})
56124
})
57125

app/services/externalAccounts.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ import _ from 'lodash'
194194
} else {
195195
logger.error('Unsupported social login backend', provider)
196196

197-
reject({
197+
$q.reject({
198198
status: 'failed',
199199
'error': 'Unsupported social login backend \'' + provider + '\''
200200
})

0 commit comments

Comments
 (0)