Replace mailgun adapter with mock adapter (#7321)
This commit is contained in:
@@ -91,77 +91,76 @@ describe('server', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can load email adapter via object', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: MockEmailAdapterWithOptions({
|
||||
fromAddress: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
}),
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(done, fail);
|
||||
});
|
||||
|
||||
it('can load email adapter via class', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
class: MockEmailAdapterWithOptions,
|
||||
options: {
|
||||
describe('mail adapter', () => {
|
||||
it('can load email adapter via object', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: MockEmailAdapterWithOptions({
|
||||
fromAddress: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
},
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(done, fail);
|
||||
});
|
||||
|
||||
it('can load email adapter via module name', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
module: '@parse/simple-mailgun-adapter',
|
||||
options: {
|
||||
fromAddress: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
},
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(done, fail);
|
||||
});
|
||||
|
||||
it('can load email adapter via only module name', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: '@parse/simple-mailgun-adapter',
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).catch(error => {
|
||||
expect(error).toEqual('SimpleMailgunAdapter requires an API Key, domain, and fromAddress.');
|
||||
done();
|
||||
}),
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(done, fail);
|
||||
});
|
||||
});
|
||||
|
||||
it('throws if you initialize email adapter incorrectly', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
module: '@parse/simple-mailgun-adapter',
|
||||
options: {
|
||||
domain: 'd',
|
||||
it('can load email adapter via class', done => {
|
||||
reconfigureServer({
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
class: MockEmailAdapterWithOptions,
|
||||
options: {
|
||||
fromAddress: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
},
|
||||
},
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).catch(error => {
|
||||
expect(error).toEqual('SimpleMailgunAdapter requires an API Key, domain, and fromAddress.');
|
||||
done();
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(done, fail);
|
||||
});
|
||||
|
||||
it('can load email adapter via module name', async () => {
|
||||
const options = {
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
module: 'mock-mail-adapter',
|
||||
options: {},
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
};
|
||||
await reconfigureServer(options);
|
||||
const config = Config.get('test');
|
||||
const mailAdapter = config.userController.adapter;
|
||||
expect(mailAdapter.sendMail).toBeDefined();
|
||||
});
|
||||
|
||||
it('can load email adapter via only module name', async () => {
|
||||
const options = {
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: 'mock-mail-adapter',
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
};
|
||||
await reconfigureServer(options);
|
||||
const config = Config.get('test');
|
||||
const mailAdapter = config.userController.adapter;
|
||||
expect(mailAdapter.sendMail).toBeDefined();
|
||||
});
|
||||
|
||||
it('throws if you initialize email adapter incorrectly', async () => {
|
||||
const options = {
|
||||
appName: 'unused',
|
||||
verifyUserEmails: true,
|
||||
emailAdapter: {
|
||||
module: 'mock-mail-adapter',
|
||||
options: { throw: true },
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
};
|
||||
expectAsync(reconfigureServer(options)).toBeRejected('MockMailAdapterConstructor');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
15
spec/support/MockMailAdapter/index.js
Normal file
15
spec/support/MockMailAdapter/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* A mock mail adapter for testing.
|
||||
*/
|
||||
class MockMailAdapter {
|
||||
constructor(options = {}) {
|
||||
if (options.throw) {
|
||||
throw 'MockMailAdapterConstructor';
|
||||
}
|
||||
}
|
||||
sendMail() {
|
||||
return 'MockMailAdapterSendMail';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MockMailAdapter;
|
||||
6
spec/support/MockMailAdapter/package.json
Normal file
6
spec/support/MockMailAdapter/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "mock-mail-adapter",
|
||||
"version": "1.0.0",
|
||||
"description": "Mock mail adapter for tests.",
|
||||
"main": "index.js"
|
||||
}
|
||||
Reference in New Issue
Block a user