|
1 | 1 | 'use strict';
|
2 |
| - |
| 2 | +const UserController = require('../lib/Controllers/UserController') |
| 3 | + .UserController; |
| 4 | +const Config = require('../lib/Config'); |
3 | 5 | describe('ParseLiveQuery', function () {
|
4 | 6 | it('can subscribe to query', async done => {
|
5 | 7 | await reconfigureServer({
|
@@ -241,6 +243,62 @@ describe('ParseLiveQuery', function () {
|
241 | 243 | }, 1000);
|
242 | 244 | });
|
243 | 245 |
|
| 246 | + it('should execute live query update on email validation', async done => { |
| 247 | + const emailAdapter = { |
| 248 | + sendVerificationEmail: () => {}, |
| 249 | + sendPasswordResetEmail: () => Promise.resolve(), |
| 250 | + sendMail: () => {}, |
| 251 | + }; |
| 252 | + |
| 253 | + await reconfigureServer({ |
| 254 | + liveQuery: { |
| 255 | + classNames: ['_User'], |
| 256 | + }, |
| 257 | + startLiveQueryServer: true, |
| 258 | + verbose: false, |
| 259 | + silent: true, |
| 260 | + websocketTimeout: 100, |
| 261 | + appName: 'liveQueryEmailValidation', |
| 262 | + verifyUserEmails: true, |
| 263 | + emailAdapter: emailAdapter, |
| 264 | + emailVerifyTokenValidityDuration: 20, // 0.5 second |
| 265 | + publicServerURL: 'http://localhost:8378/1', |
| 266 | + }).then(() => { |
| 267 | + const user = new Parse.User(); |
| 268 | + user.set('password', 'asdf'); |
| 269 | + user.set('email', '[email protected]'); |
| 270 | + user.set('username', 'zxcv'); |
| 271 | + user |
| 272 | + .signUp() |
| 273 | + .then(() => { |
| 274 | + const config = Config.get('test'); |
| 275 | + return config.database.find('_User', { |
| 276 | + username: 'zxcv', |
| 277 | + }); |
| 278 | + }) |
| 279 | + .then(async results => { |
| 280 | + const foundUser = results[0]; |
| 281 | + const query = new Parse.Query('_User'); |
| 282 | + query.equalTo('objectId', foundUser.objectId); |
| 283 | + const subscription = await query.subscribe(); |
| 284 | + |
| 285 | + subscription.on('update', async object => { |
| 286 | + expect(object).toBeDefined(); |
| 287 | + expect(object.get('emailVerified')).toBe(true); |
| 288 | + done(); |
| 289 | + }); |
| 290 | + |
| 291 | + const userController = new UserController(emailAdapter, 'test', { |
| 292 | + verifyUserEmails: true, |
| 293 | + }); |
| 294 | + userController.verifyEmail( |
| 295 | + foundUser.username, |
| 296 | + foundUser._email_verify_token |
| 297 | + ); |
| 298 | + }); |
| 299 | + }); |
| 300 | + }); |
| 301 | + |
244 | 302 | afterEach(async function (done) {
|
245 | 303 | const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
|
246 | 304 | client.close();
|
|
0 commit comments