1
1
import {
2
2
authDataToAuthState ,
3
3
AuthProviders ,
4
- FirebaseAuthState ,
5
- CommonOAuthCredential ,
6
- GoogleCredential ,
7
- TwitterCredential
4
+ FirebaseAuthState
8
5
} from './auth_backend' ;
9
6
10
7
const baseFBUser = {
@@ -25,94 +22,93 @@ const baseAuthState: FirebaseAuthState = {
25
22
auth : < firebase . User > baseFBUser
26
23
} ;
27
24
28
- const baseGithubCredential : CommonOAuthCredential = {
29
- accessToken : 'GH_ACCESS_TOKEN ' ,
30
- provider : 'github.com '
31
- } ;
25
+ const baseGithubCredential = {
26
+ providerId : 'github.com ' ,
27
+ displayName : 'GithubAlice '
28
+ } as firebase . UserInfo ;
32
29
33
- const baseFacebookCredential : CommonOAuthCredential = {
34
- accessToken : 'FB_ACCESS_TOKEN ' ,
35
- provider : 'facebook.com'
36
- } ;
30
+ const baseFacebookCredential = {
31
+ displayName : 'FacebookFranny ' ,
32
+ providerId : 'facebook.com'
33
+ } as firebase . UserInfo ;
37
34
38
- const baseGoogleCredential : GoogleCredential = {
39
- idToken : 'GOOGLE_ID_TOKEN ' ,
40
- provider : 'google.com'
41
- } ;
35
+ const baseGoogleCredential = {
36
+ displayName : 'GoogleGerry ' ,
37
+ providerId : 'google.com'
38
+ } as firebase . UserInfo ;
42
39
43
- const baseTwitterCredential : TwitterCredential = {
44
- accessToken : 'TWITTER_ACCESS_TOKEN' ,
45
- provider : 'twitter.com' ,
46
- secret : 'TWITTER_SECRET'
47
- } ;
40
+ const baseTwitterCredential = {
41
+ displayName : 'TwitterTiffany' ,
42
+ providerId : 'twitter.com' ,
43
+ } as firebase . UserInfo ;
48
44
49
45
describe ( 'auth_backend' , ( ) => {
50
46
describe ( 'authDataToAuthState' , ( ) => {
51
47
it ( 'Github: should return a FirebaseAuthState object with full provider data' , ( ) => {
52
48
let githubUser = Object . assign ( { } , baseFBUser , {
53
49
providerData : [ { providerId : 'github.com' } ]
54
- } ) ;
50
+ } ) as firebase . User ;
55
51
let expectedAuthState = Object . assign ( { } , baseAuthState , {
56
52
github : baseGithubCredential ,
57
53
auth : githubUser
58
54
} ) ;
59
55
60
56
let actualAuthState = authDataToAuthState ( githubUser , baseGithubCredential ) ;
61
- expect ( actualAuthState . github . accessToken ) . toEqual ( baseGithubCredential . accessToken ) ;
57
+ expect ( actualAuthState . github . displayName ) . toEqual ( baseGithubCredential . displayName ) ;
62
58
} ) ;
63
59
} ) ;
64
60
65
61
it ( 'Google: should return a FirebaseAuthState object with full provider data' , ( ) => {
66
62
let googleUser = Object . assign ( { } , baseFBUser , {
67
63
providerData : [ { providerId : 'google.com' } ]
68
- } ) ;
64
+ } ) as firebase . User ;
69
65
let expectedAuthState = Object . assign ( { } , baseAuthState , {
70
66
google : baseGoogleCredential ,
71
67
auth : googleUser
72
68
} ) ;
73
69
74
70
let actualAuthState = authDataToAuthState ( googleUser , baseGoogleCredential ) ;
75
- expect ( actualAuthState . google . idToken ) . toEqual ( baseGoogleCredential . idToken ) ;
71
+ expect ( actualAuthState . google . displayName ) . toEqual ( baseGoogleCredential . displayName ) ;
76
72
} ) ;
77
73
78
74
it ( 'Twitter: should return a FirebaseAuthState object with full provider data' , ( ) => {
79
75
let twitterUser = Object . assign ( { } , baseFBUser , {
80
76
providerData : [ { providerId : 'twitter.com' } ]
81
- } ) ;
77
+ } ) as firebase . User ;
82
78
let expectedAuthState = Object . assign ( { } , baseAuthState , {
83
79
twitter : baseTwitterCredential ,
84
80
auth : twitterUser
85
81
} ) ;
86
82
87
83
let actualAuthState = authDataToAuthState ( twitterUser , baseTwitterCredential ) ;
88
- expect ( actualAuthState . twitter . secret ) . toEqual ( baseTwitterCredential . secret ) ;
84
+ expect ( actualAuthState . twitter . displayName ) . toEqual ( baseTwitterCredential . displayName ) ;
89
85
} ) ;
90
86
91
87
it ( 'Facebook: should return a FirebaseAuthState object with full provider data' , ( ) => {
92
88
let facebookUser = Object . assign ( { } , baseFBUser , {
93
89
providerData : [ { providerId : 'facebook.com' } ]
94
- } ) ;
90
+ } ) as firebase . User ;
95
91
let expectedAuthState = Object . assign ( { } , baseAuthState , {
96
92
facebook : baseFacebookCredential ,
97
93
auth : facebookUser
98
94
} ) ;
99
95
100
96
let actualAuthState = authDataToAuthState ( facebookUser , baseFacebookCredential ) ;
101
- expect ( actualAuthState . facebook . accessToken ) . toEqual ( baseFacebookCredential . accessToken ) ;
97
+ expect ( actualAuthState . facebook . displayName ) . toEqual ( baseFacebookCredential . displayName ) ;
102
98
} ) ;
103
99
104
100
105
101
it ( 'Anonymous: should return a FirebaseAuthState object' , ( ) => {
106
- let anonymouseFirebaseUser = Object . assign ( { } , baseFBUser , {
102
+ let anonymousFirebaseUser = Object . assign ( { } , baseFBUser , {
107
103
providerData : [ ] ,
108
104
isAnonymous : true
109
- } ) ;
105
+ } ) as firebase . User ;
110
106
let expectedAuthState = Object . assign ( { } , baseAuthState , {
111
107
facebook : baseFacebookCredential ,
112
- auth : anonymouseFirebaseUser
108
+ auth : anonymousFirebaseUser
113
109
} ) ;
114
110
115
- let actualAuthState = authDataToAuthState ( anonymouseFirebaseUser ) ;
111
+ let actualAuthState = authDataToAuthState ( anonymousFirebaseUser ) ;
116
112
expect ( actualAuthState . anonymous ) . toEqual ( true ) ;
117
113
} ) ;
118
114
} ) ;
0 commit comments