@@ -72,7 +72,49 @@ describe('Parse.User testing', () => {
72
72
user . signUp ( null , {
73
73
success : function ( user ) {
74
74
expect ( emailAdapter . sendVerificationEmail ) . toHaveBeenCalled ( ) ;
75
+ user . fetch ( )
76
+ . then ( ( ) => {
77
+ expect ( user . get ( 'emailVerified' ) ) . toEqual ( false ) ;
78
+ done ( ) ;
79
+ } ) ;
80
+ } ,
81
+ error : function ( userAgain , error ) {
82
+ fail ( 'Failed to save user' ) ;
75
83
done ( ) ;
84
+ }
85
+ } ) ;
86
+ } ) ;
87
+
88
+ it ( 'does not send verification email if email verification is disabled' , done => {
89
+ var emailAdapter = {
90
+ sendVerificationEmail : ( ) => Promise . resolve ( )
91
+ }
92
+ setServerConfiguration ( {
93
+ serverURL : 'http://localhost:8378/1' ,
94
+ appId : 'test' ,
95
+ appName : 'unused' ,
96
+ javascriptKey : 'test' ,
97
+ dotNetKey : 'windows' ,
98
+ clientKey : 'client' ,
99
+ restAPIKey : 'rest' ,
100
+ masterKey : 'test' ,
101
+ collectionPrefix : 'test_' ,
102
+ fileKey : 'test' ,
103
+ verifyUserEmails : false ,
104
+ emailAdapter : emailAdapter ,
105
+ } ) ;
106
+ spyOn ( emailAdapter , 'sendVerificationEmail' ) ;
107
+ var user = new Parse . User ( ) ;
108
+ user . setPassword ( "asdf" ) ;
109
+ user . setUsername ( "zxcv" ) ;
110
+ user . signUp ( null , {
111
+ success : function ( user ) {
112
+ user . fetch ( )
113
+ . then ( ( ) => {
114
+ expect ( emailAdapter . sendVerificationEmail . calls . count ( ) ) . toEqual ( 0 ) ;
115
+ expect ( user . get ( 'emailVerified' ) ) . toEqual ( undefined ) ;
116
+ done ( ) ;
117
+ } ) ;
76
118
} ,
77
119
error : function ( userAgain , error ) {
78
120
fail ( 'Failed to save user' ) ;
@@ -81,6 +123,141 @@ describe('Parse.User testing', () => {
81
123
} ) ;
82
124
} ) ;
83
125
126
+ it ( 'receives the app name and user in the adapter' , done => {
127
+ var emailAdapter = {
128
+ sendVerificationEmail : options => {
129
+ expect ( options . appName ) . toEqual ( 'emailing app' ) ;
130
+ expect ( options . user . get ( 'email' ) ) . toEqual ( '[email protected] ' ) ;
131
+ done ( ) ;
132
+ }
133
+ }
134
+ setServerConfiguration ( {
135
+ serverURL : 'http://localhost:8378/1' ,
136
+ appId : 'test' ,
137
+ appName : 'emailing app' ,
138
+ javascriptKey : 'test' ,
139
+ dotNetKey : 'windows' ,
140
+ clientKey : 'client' ,
141
+ restAPIKey : 'rest' ,
142
+ masterKey : 'test' ,
143
+ collectionPrefix : 'test_' ,
144
+ fileKey : 'test' ,
145
+ verifyUserEmails : true ,
146
+ emailAdapter : emailAdapter ,
147
+ } ) ;
148
+ var user = new Parse . User ( ) ;
149
+ user . setPassword ( "asdf" ) ;
150
+ user . setUsername ( "zxcv" ) ;
151
+ user . set ( 'email' , '[email protected] ' ) ;
152
+ user . signUp ( null , {
153
+ success : ( ) => { } ,
154
+ error : function ( userAgain , error ) {
155
+ fail ( 'Failed to save user' ) ;
156
+ done ( ) ;
157
+ }
158
+ } ) ;
159
+ } )
160
+
161
+ it ( 'when you click the link in the email it sets emailVerified to true and redirects you' , done => {
162
+ var user = new Parse . User ( ) ;
163
+ var emailAdapter = {
164
+ sendVerificationEmail : options => {
165
+ request . get ( options . link , {
166
+ followRedirect : false ,
167
+ } , ( error , response , body ) => {
168
+ expect ( response . statusCode ) . toEqual ( 302 ) ;
169
+ expect ( response . body ) . toEqual ( 'Found. Redirecting to http://localhost:8378/1/verify_email_success.html?username=zxcv' ) ;
170
+ user . fetch ( )
171
+ . then ( ( ) => {
172
+ expect ( user . get ( 'emailVerified' ) ) . toEqual ( true ) ;
173
+ done ( ) ;
174
+ } ) ;
175
+ } ) ;
176
+ }
177
+ }
178
+ setServerConfiguration ( {
179
+ serverURL : 'http://localhost:8378/1' ,
180
+ appId : 'test' ,
181
+ appName : 'emailing app' ,
182
+ javascriptKey : 'test' ,
183
+ dotNetKey : 'windows' ,
184
+ clientKey : 'client' ,
185
+ restAPIKey : 'rest' ,
186
+ masterKey : 'test' ,
187
+ collectionPrefix : 'test_' ,
188
+ fileKey : 'test' ,
189
+ verifyUserEmails : true ,
190
+ emailAdapter : emailAdapter ,
191
+ } ) ;
192
+ user . setPassword ( "asdf" ) ;
193
+ user . setUsername ( "zxcv" ) ;
194
+ user . set ( 'email' , '[email protected] ' ) ;
195
+ user . signUp ( ) ;
196
+ } ) ;
197
+
198
+ it ( 'redirects you to invalid link if you try to verify email incorrecly' , done => {
199
+ request . get ( 'http://localhost:8378/1/verify_email' , {
200
+ followRedirect : false ,
201
+ } , ( error , response , body ) => {
202
+ expect ( response . statusCode ) . toEqual ( 302 ) ;
203
+ expect ( response . body ) . toEqual ( 'Found. Redirecting to http://localhost:8378/1/invalid_link.html' ) ;
204
+ done ( )
205
+ } ) ;
206
+ } ) ;
207
+
208
+ it ( 'redirects you to invalid link if you try to validate a nonexistant users email' , done => {
209
+ request . get ( 'http://localhost:8378/1/verify_email?token=asdfasdf&username=sadfasga' , {
210
+ followRedirect : false ,
211
+ } , ( error , response , body ) => {
212
+ expect ( response . statusCode ) . toEqual ( 302 ) ;
213
+ expect ( response . body ) . toEqual ( 'Found. Redirecting to http://localhost:8378/1/invalid_link.html' ) ;
214
+ done ( ) ;
215
+ } ) ;
216
+ } ) ;
217
+
218
+ it ( 'does not update email verified if you use an invalid token' , done => {
219
+ var user = new Parse . User ( ) ;
220
+ var emailAdapter = {
221
+ sendVerificationEmail : options => {
222
+ request . get ( 'http://localhost:8378/1/verify_email?token=invalid&username=zxcv' , {
223
+ followRedirect : false ,
224
+ } , ( error , response , body ) => {
225
+ expect ( response . statusCode ) . toEqual ( 302 ) ;
226
+ expect ( response . body ) . toEqual ( 'Found. Redirecting to http://localhost:8378/1/invalid_link.html' ) ;
227
+ user . fetch ( )
228
+ . then ( ( ) => {
229
+ expect ( user . get ( 'emailVerified' ) ) . toEqual ( false ) ;
230
+ done ( ) ;
231
+ } ) ;
232
+ } ) ;
233
+ }
234
+ }
235
+ setServerConfiguration ( {
236
+ serverURL : 'http://localhost:8378/1' ,
237
+ appId : 'test' ,
238
+ appName : 'emailing app' ,
239
+ javascriptKey : 'test' ,
240
+ dotNetKey : 'windows' ,
241
+ clientKey : 'client' ,
242
+ restAPIKey : 'rest' ,
243
+ masterKey : 'test' ,
244
+ collectionPrefix : 'test_' ,
245
+ fileKey : 'test' ,
246
+ verifyUserEmails : true ,
247
+ emailAdapter : emailAdapter ,
248
+ } ) ;
249
+ user . setPassword ( "asdf" ) ;
250
+ user . setUsername ( "zxcv" ) ;
251
+ user . set ( 'email' , '[email protected] ' ) ;
252
+ user . signUp ( null , {
253
+ success : ( ) => { } ,
254
+ error : function ( userAgain , error ) {
255
+ fail ( 'Failed to save user' ) ;
256
+ done ( ) ;
257
+ }
258
+ } ) ;
259
+ } ) ;
260
+
84
261
it ( "user login wrong username" , ( done ) => {
85
262
Parse . User . signUp ( "asdf" , "zxcv" , null , {
86
263
success : function ( user ) {
0 commit comments