Skip to content

Commit f65046c

Browse files
committed
Tests for invalid config
1 parent bfb96e2 commit f65046c

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

spec/EmailVerificationToken.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,45 @@ describe('Email Verification Token Expiration: ', () => {
604604
});
605605
});
606606

607+
it('should throw with invalid emailVerifyTokenReuseIfValid', async done => {
608+
const sendEmailOptions = [];
609+
const emailAdapter = {
610+
sendVerificationEmail: () => Promise.resolve(),
611+
sendPasswordResetEmail: options => {
612+
sendEmailOptions.push(options);
613+
},
614+
sendMail: () => {},
615+
};
616+
try {
617+
await reconfigureServer({
618+
appName: 'passwordPolicy',
619+
verifyUserEmails: true,
620+
emailAdapter: emailAdapter,
621+
emailVerifyTokenValidityDuration: 5 * 60, // 5 minutes
622+
emailVerifyTokenReuseIfValid: [],
623+
publicServerURL: 'http://localhost:8378/1',
624+
});
625+
fail('should have thrown.');
626+
} catch (e) {
627+
expect(e).toBe('emailVerifyTokenReuseIfValid must be a boolean value');
628+
}
629+
try {
630+
await reconfigureServer({
631+
appName: 'passwordPolicy',
632+
verifyUserEmails: true,
633+
emailAdapter: emailAdapter,
634+
emailVerifyTokenReuseIfValid: true,
635+
publicServerURL: 'http://localhost:8378/1',
636+
});
637+
fail('should have thrown.');
638+
} catch (e) {
639+
expect(e).toBe(
640+
'You cannot use emailVerifyTokenReuseIfValid without emailVerifyTokenValidityDuration'
641+
);
642+
}
643+
done();
644+
});
645+
607646
it('should match codes with emailVerifyTokenReuseIfValid', async done => {
608647
let sendEmailOptions;
609648
let sendVerificationEmailCallCount = 0;

spec/PasswordPolicy.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,45 @@ describe('Password Policy: ', () => {
179179
done();
180180
});
181181

182+
it('should throw with invalid resetTokenReuseIfValid', async done => {
183+
const sendEmailOptions = [];
184+
const emailAdapter = {
185+
sendVerificationEmail: () => Promise.resolve(),
186+
sendPasswordResetEmail: options => {
187+
sendEmailOptions.push(options);
188+
},
189+
sendMail: () => {},
190+
};
191+
try {
192+
await reconfigureServer({
193+
appName: 'passwordPolicy',
194+
emailAdapter: emailAdapter,
195+
passwordPolicy: {
196+
resetTokenValidityDuration: 5 * 60, // 5 minutes
197+
resetTokenReuseIfValid: [],
198+
},
199+
publicServerURL: 'http://localhost:8378/1',
200+
});
201+
fail('should have thrown.');
202+
} catch (e) {
203+
expect(e).toBe('resetTokenReuseIfValid must be a boolean value');
204+
}
205+
try {
206+
await reconfigureServer({
207+
appName: 'passwordPolicy',
208+
emailAdapter: emailAdapter,
209+
passwordPolicy: {
210+
resetTokenReuseIfValid: true,
211+
},
212+
publicServerURL: 'http://localhost:8378/1',
213+
});
214+
fail('should have thrown.');
215+
} catch (e) {
216+
expect(e).toBe('You cannot use resetTokenReuseIfValid without resetTokenValidityDuration');
217+
}
218+
done();
219+
});
220+
182221
it('should fail if passwordPolicy.resetTokenValidityDuration is not a number', done => {
183222
reconfigureServer({
184223
appName: 'passwordPolicy',

0 commit comments

Comments
 (0)