@@ -7,7 +7,7 @@ describe('ExternalAccount Service', function() {
7
7
var mockProfile = mockData . getMockProfile ( ) ;
8
8
var apiUrl ;
9
9
var auth0 , userService ;
10
- var profilePost , profileDelete ;
10
+ var profileGet , profilePost , profileDelete ;
11
11
12
12
13
13
beforeEach ( function ( ) {
@@ -46,9 +46,10 @@ describe('ExternalAccount Service', function() {
46
46
$httpBackend
47
47
. when ( 'GET' , apiUrl + '/members/test1/externalAccounts/' )
48
48
. respond ( 200 , { result : { content : mockAccountsData } } ) ;
49
- $httpBackend
50
- . when ( 'GET' , apiUrl + '/users/111/?fields=profiles' )
51
- . respond ( 200 , { result : { content : mockUserLinksData } } ) ;
49
+
50
+ profileGet = $httpBackend . when ( 'GET' , apiUrl + '/users/111/?fields=profiles' ) ;
51
+ profileGet . respond ( 200 , { result : { content : mockUserLinksData } } ) ;
52
+
52
53
profilePost = $httpBackend . when ( 'POST' , apiUrl + '/users/111/profiles/' ) ;
53
54
profilePost . respond ( 200 , { result : { content : mockProfile } } ) ;
54
55
@@ -104,6 +105,33 @@ describe('ExternalAccount Service', function() {
104
105
$httpBackend . flush ( ) ;
105
106
} ) ;
106
107
108
+ it ( 'should not return unsupported links even if they are returned by the API' , function ( ) {
109
+ var profiles = JSON . parse ( JSON . stringify ( mockUserLinksData ) ) ;
110
+ profiles . profiles . push ( { providerType : 'unsupported' } ) ;
111
+ profileGet . respond ( 200 , { result : { content : profiles } } ) ;
112
+ // spy
113
+ service . getAllExternalLinks ( 'test1' , 111 , true ) . then ( function ( data ) {
114
+ expect ( data ) . to . be . defined ;
115
+ expect ( _ . pluck ( data , 'provider' ) ) . to . include . members ( [ 'dribbble' , 'github' , 'bitbucket' , 'stackoverflow' ] ) ;
116
+ expect ( _ . all ( _ . pluck ( data , 'data' ) ) ) . to . be . truthy ;
117
+ } ) ;
118
+ $httpBackend . flush ( ) ;
119
+ } ) ;
120
+
121
+ it ( 'should fail in returning links' , function ( ) {
122
+ var errorMessage = "bad request" ;
123
+ // mocks the GET call to respond with 400 bad request
124
+ profileGet . respond ( 400 , { result : { status : 400 , content : errorMessage } } ) ;
125
+ // calls getAllExternalLinks method with valid params
126
+ service . getAllExternalLinks ( 'test1' , 111 , true ) . then ( function ( data ) {
127
+ sinon . assert . fail ( 'should not be called' ) ;
128
+ } ) . catch ( function ( resp ) {
129
+ expect ( resp ) . to . exist ;
130
+ expect ( resp . status ) . to . exist . to . equal ( 400 ) ;
131
+ } ) ;
132
+ $httpBackend . flush ( ) ;
133
+ } ) ;
134
+
107
135
it ( 'should link external account' , function ( ) {
108
136
// call linkExternalAccount method with supporte network, should succeed
109
137
service . linkExternalAccount ( 'stackoverflow' , "callback" ) . then ( function ( data ) {
@@ -151,6 +179,20 @@ describe('ExternalAccount Service', function() {
151
179
$httpBackend . flush ( ) ;
152
180
} ) ;
153
181
182
+ it ( 'should fail, with fatal error, in linking external account' , function ( ) {
183
+ var errorMessage = "endpoint not found" ;
184
+ profilePost . respond ( 404 , { result : { status : 404 , content : errorMessage } } ) ;
185
+ // call unlinkExternalAccount method with supporte network, should succeed
186
+ service . linkExternalAccount ( 'stackoverflow' , "callback" ) . then ( function ( data ) {
187
+ sinon . assert . fail ( 'should not be called' ) ;
188
+ } ) . catch ( function ( error ) {
189
+ expect ( error ) . to . be . defined ;
190
+ expect ( error . status ) . to . exist . to . equal ( 'FATAL_ERROR' ) ;
191
+ expect ( error . msg ) . to . exist . to . equal ( errorMessage ) ;
192
+ } ) ;
193
+ $httpBackend . flush ( ) ;
194
+ } ) ;
195
+
154
196
it ( 'should unlink external account' , function ( ) {
155
197
var errorMessage = "social profile exists" ;
156
198
profilePost . respond ( 400 , { result : { status : 400 , content : errorMessage } } ) ;
0 commit comments