test: make email requirement flag changes more explicit in tests, so cases do not rely on variable values from other cases

isekai-main
Julian Lam 2 years ago
parent 7a0e5c6d9a
commit a8399aa23a

@ -402,6 +402,8 @@ describe('Controllers', () => {
assert(!res.body.errors.includes('[[error:invalid-email]]'));
assert(!res.body.errors.includes('[[error:gdpr_consent_denied]]'));
meta.config.requireEmailAddress = 1;
});
it('should error if userData is falsy', async () => {
@ -427,7 +429,6 @@ describe('Controllers', () => {
});
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 result = await user.interstitials.email({
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;
const uid = await user.create({ username: 'interstiuser5' });
await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org');
await user.email.confirmByUid(uid);
@ -506,6 +508,8 @@ describe('Controllers', () => {
const userData = await user.getUserData(uid);
assert.strictEqual(userData.email, '');
assert.strictEqual(userData['email:confirmed'], 0);
meta.config.requireEmailAddress = 1;
});
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 () => {
meta.config.requireEmailAddress = 0;
try {
const [username, password] = [utils.generateUUID().slice(0, 10), utils.generateUUID()];
const uid = await user.create({ username, password });
@ -548,6 +554,8 @@ describe('Controllers', () => {
} catch (err) {
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 () => {

Loading…
Cancel
Save