@@ -26,16 +26,11 @@ import { testAuth } from '../../../test/mock_auth';
26
26
import * as mockFetch from '../../../test/mock_fetch' ;
27
27
import { Auth } from '../../model/auth' ;
28
28
import { ServerError } from '../errors' ;
29
- import { signInWithEmailLink } from './email_link' ;
29
+ import { signInWithEmailLink , signInWithEmailLinkForLinking } from './email_link' ;
30
30
31
31
use ( chaiAsPromised ) ;
32
32
33
- describe ( 'api/authentication/signInWithEmailLink' , ( ) => {
34
- const request = {
35
-
36
- oobCode : 'my-code'
37
- } ;
38
-
33
+ describe ( 'api/authentication/email_link' , ( ) => {
39
34
let auth : Auth ;
40
35
41
36
beforeEach ( async ( ) => {
@@ -45,44 +40,101 @@ describe('api/authentication/signInWithEmailLink', () => {
45
40
46
41
afterEach ( mockFetch . tearDown ) ;
47
42
48
- it ( 'should POST to the correct endpoint' , async ( ) => {
49
- const mock = mockEndpoint ( Endpoint . SIGN_IN_WITH_EMAIL_LINK , {
50
- displayName : 'my-name' ,
51
-
43
+
44
+ context ( 'signInWithEmailLink' , ( ) => {
45
+ const request = {
46
+
47
+ oobCode : 'my-code'
48
+ } ;
49
+
50
+ it ( 'should POST to the correct endpoint' , async ( ) => {
51
+ const mock = mockEndpoint ( Endpoint . SIGN_IN_WITH_EMAIL_LINK , {
52
+ displayName : 'my-name' ,
53
+
54
+ } ) ;
55
+
56
+ const response = await signInWithEmailLink ( auth , request ) ;
57
+ expect ( response . displayName ) . to . eq ( 'my-name' ) ;
58
+ expect ( response . email ) . to . eq ( '[email protected] ' ) ;
59
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
60
+ expect ( mock . calls [ 0 ] . method ) . to . eq ( 'POST' ) ;
61
+ expect ( mock . calls [ 0 ] . headers ) . to . eql ( {
62
+ 'Content-Type' : 'application/json' ,
63
+ 'X-Client-Version' : 'testSDK/0.0.0'
64
+ } ) ;
52
65
} ) ;
53
66
54
- const response = await signInWithEmailLink ( auth , request ) ;
55
- expect ( response . displayName ) . to . eq ( 'my-name' ) ;
56
- expect ( response . email ) . to . eq ( '[email protected] ' ) ;
57
- expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
58
- expect ( mock . calls [ 0 ] . method ) . to . eq ( 'POST' ) ;
59
- expect ( mock . calls [ 0 ] . headers ) . to . eql ( {
60
- 'Content-Type' : 'application/json' ,
61
- 'X-Client-Version' : 'testSDK/0.0.0'
67
+ it ( 'should handle errors' , async ( ) => {
68
+ const mock = mockEndpoint (
69
+ Endpoint . SIGN_IN_WITH_EMAIL_LINK ,
70
+ {
71
+ error : {
72
+ code : 400 ,
73
+ message : ServerError . INVALID_EMAIL ,
74
+ errors : [
75
+ {
76
+ message : ServerError . INVALID_EMAIL
77
+ }
78
+ ]
79
+ }
80
+ } ,
81
+ 400
82
+ ) ;
83
+
84
+ await expect ( signInWithEmailLink ( auth , request ) ) . to . be . rejectedWith (
85
+ FirebaseError ,
86
+ 'Firebase: The email address is badly formatted. (auth/invalid-email).'
87
+ ) ;
88
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
62
89
} ) ;
63
90
} ) ;
64
91
65
- it ( 'should handle errors' , async ( ) => {
66
- const mock = mockEndpoint (
67
- Endpoint . SIGN_IN_WITH_EMAIL_LINK ,
68
- {
69
- error : {
70
- code : 400 ,
71
- message : ServerError . INVALID_EMAIL ,
72
- errors : [
73
- {
74
- message : ServerError . INVALID_EMAIL
75
- }
76
- ]
77
- }
78
- } ,
79
- 400
80
- ) ;
81
-
82
- await expect ( signInWithEmailLink ( auth , request ) ) . to . be . rejectedWith (
83
- FirebaseError ,
84
- 'Firebase: The email address is badly formatted. (auth/invalid-email).'
85
- ) ;
86
- expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
92
+ context ( 'signInWithEmailLinkForLinking' , ( ) => {
93
+ const request = {
94
+
95
+ oobCode : 'my-code' ,
96
+ idToken : 'id-token-2' ,
97
+ } ;
98
+
99
+ it ( 'should POST to the correct endpoint' , async ( ) => {
100
+ const mock = mockEndpoint ( Endpoint . SIGN_IN_WITH_EMAIL_LINK , {
101
+ displayName : 'my-name' ,
102
+
103
+ } ) ;
104
+
105
+ const response = await signInWithEmailLinkForLinking ( auth , request ) ;
106
+ expect ( response . displayName ) . to . eq ( 'my-name' ) ;
107
+ expect ( response . email ) . to . eq ( '[email protected] ' ) ;
108
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
109
+ expect ( mock . calls [ 0 ] . method ) . to . eq ( 'POST' ) ;
110
+ expect ( mock . calls [ 0 ] . headers ) . to . eql ( {
111
+ 'Content-Type' : 'application/json' ,
112
+ 'X-Client-Version' : 'testSDK/0.0.0'
113
+ } ) ;
114
+ } ) ;
115
+
116
+ it ( 'should handle errors' , async ( ) => {
117
+ const mock = mockEndpoint (
118
+ Endpoint . SIGN_IN_WITH_EMAIL_LINK ,
119
+ {
120
+ error : {
121
+ code : 400 ,
122
+ message : ServerError . INVALID_EMAIL ,
123
+ errors : [
124
+ {
125
+ message : ServerError . INVALID_EMAIL
126
+ }
127
+ ]
128
+ }
129
+ } ,
130
+ 400
131
+ ) ;
132
+
133
+ await expect ( signInWithEmailLinkForLinking ( auth , request ) ) . to . be . rejectedWith (
134
+ FirebaseError ,
135
+ 'Firebase: The email address is badly formatted. (auth/invalid-email).'
136
+ ) ;
137
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
138
+ } ) ;
87
139
} ) ;
88
140
} ) ;
0 commit comments