mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	test: make email requirement flag changes more explicit in tests, so cases do not rely on variable values from other cases
This commit is contained in:
		| @@ -402,6 +402,8 @@ describe('Controllers', () => { | |||||||
|  |  | ||||||
| 				assert(!res.body.errors.includes('[[error:invalid-email]]')); | 				assert(!res.body.errors.includes('[[error:invalid-email]]')); | ||||||
| 				assert(!res.body.errors.includes('[[error:gdpr_consent_denied]]')); | 				assert(!res.body.errors.includes('[[error:gdpr_consent_denied]]')); | ||||||
|  |  | ||||||
|  | 				meta.config.requireEmailAddress = 1; | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should error if userData is falsy', async () => { | 			it('should error if userData is falsy', async () => { | ||||||
| @@ -427,7 +429,6 @@ describe('Controllers', () => { | |||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should reject an email that comprises only whitespace', async () => { | 			it('should reject an email that comprises only whitespace', async () => { | ||||||
| 				meta.config.requireEmailAddress = 1; |  | ||||||
| 				const uid = await user.create({ username: utils.generateUUID().slice(0, 10) }); | 				const uid = await user.create({ username: utils.generateUUID().slice(0, 10) }); | ||||||
| 				const result = await user.interstitials.email({ | 				const result = await user.interstitials.email({ | ||||||
| 					userData: { uid: uid, updateEmail: true }, | 					userData: { uid: uid, updateEmail: true }, | ||||||
| @@ -488,8 +489,9 @@ describe('Controllers', () => { | |||||||
| 				} | 				} | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should remove current email', async () => { | 			it('should remove current email (only allowed if email not required)', async () => { | ||||||
| 				meta.config.requireEmailAddress = 0; | 				meta.config.requireEmailAddress = 0; | ||||||
|  |  | ||||||
| 				const uid = await user.create({ username: 'interstiuser5' }); | 				const uid = await user.create({ username: 'interstiuser5' }); | ||||||
| 				await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org'); | 				await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org'); | ||||||
| 				await user.email.confirmByUid(uid); | 				await user.email.confirmByUid(uid); | ||||||
| @@ -506,6 +508,8 @@ describe('Controllers', () => { | |||||||
| 				const userData = await user.getUserData(uid); | 				const userData = await user.getUserData(uid); | ||||||
| 				assert.strictEqual(userData.email, ''); | 				assert.strictEqual(userData.email, ''); | ||||||
| 				assert.strictEqual(userData['email:confirmed'], 0); | 				assert.strictEqual(userData['email:confirmed'], 0); | ||||||
|  |  | ||||||
|  | 				meta.config.requireEmailAddress = 1; | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should require a password (if one is set) for email change', async () => { | 			it('should require a password (if one is set) for email change', async () => { | ||||||
| @@ -530,6 +534,8 @@ describe('Controllers', () => { | |||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should require a password (if one is set) for email clearing', async () => { | 			it('should require a password (if one is set) for email clearing', async () => { | ||||||
|  | 				meta.config.requireEmailAddress = 0; | ||||||
|  |  | ||||||
| 				try { | 				try { | ||||||
| 					const [username, password] = [utils.generateUUID().slice(0, 10), utils.generateUUID()]; | 					const [username, password] = [utils.generateUUID().slice(0, 10), utils.generateUUID()]; | ||||||
| 					const uid = await user.create({ username, password }); | 					const uid = await user.create({ username, password }); | ||||||
| @@ -548,6 +554,8 @@ describe('Controllers', () => { | |||||||
| 				} catch (err) { | 				} catch (err) { | ||||||
| 					assert.strictEqual(err.message, '[[error:invalid-password]]'); | 					assert.strictEqual(err.message, '[[error:invalid-password]]'); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|  | 				meta.config.requireEmailAddress = 1; | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should successfully issue validation request if the correct password is passed in', async () => { | 			it('should successfully issue validation request if the correct password is passed in', async () => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user