Skip to content

Commit

Permalink
add mock email adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Jan 17, 2024
1 parent 84d5089 commit 6300142
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
11 changes: 6 additions & 5 deletions integration/test/ParseUserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const assert = require('assert');
const Parse = require('../../node');
const { v4: uuidv4 } = require('uuid');
const { twitterAuthData } = require('./helper');
const MockEmailAdapterWithOptions = require('./support/MockEmailAdapterWithOptions');

class CustomUser extends Parse.User {
constructor(attributes) {
Expand Down Expand Up @@ -1063,11 +1064,11 @@ describe('Parse User', () => {
appName: 'AppName',
verifyUserEmails: true,
preventLoginWithUnverifiedEmail: true,
emailAdapter: {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve(),
},
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: 'parse@example.com',
apiKey: 'k',
domain: 'd',
}),
});
await Parse.User.signUp('asd123', 'xyz123');
const res = await Parse.User.verifyPassword('asd123', 'xyz123', { useMasterKey: true, ignoreUnverifiedEmail: true });
Expand Down
21 changes: 21 additions & 0 deletions integration/test/support/MockEmailAdapterWithOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = options => {
if (!options) {
throw 'Options were not provided';
}
const adapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve(),
};
if (options.sendMail) {
adapter.sendMail = options.sendMail;
}
if (options.sendPasswordResetEmail) {
adapter.sendPasswordResetEmail = options.sendPasswordResetEmail;
}
if (options.sendVerificationEmail) {
adapter.sendVerificationEmail = options.sendVerificationEmail;
}

return adapter;
};

0 comments on commit 6300142

Please sign in to comment.