2018-10-12 20:44:05 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const sinon = require('sinon');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2020-03-30 18:26:47 +03:00
|
|
|
const mailService = require('../../../core/server/services/mail');
|
2018-10-12 20:44:05 +03:00
|
|
|
const localUtils = require('./utils');
|
2019-09-20 18:02:45 +03:00
|
|
|
|
2018-10-12 20:44:05 +03:00
|
|
|
const ghost = testUtils.startGhost;
|
2019-01-21 19:53:44 +03:00
|
|
|
|
2018-10-12 20:44:05 +03:00
|
|
|
let request;
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Mail API', function () {
|
|
|
|
let ghostServer;
|
2018-10-12 20:44:05 +03:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return localUtils.doAuth(request, 'invites');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.stub(mailService.GhostMailer.prototype, 'send').resolves({message: 'sent'});
|
2018-10-12 20:44:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2018-10-12 20:44:05 +03:00
|
|
|
});
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('Can send mail', function () {
|
2018-10-12 20:44:05 +03:00
|
|
|
return request
|
|
|
|
.post(localUtils.API.getApiQuery('mail/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({
|
|
|
|
mail: [{
|
|
|
|
message: {
|
|
|
|
to: 'joe@example.com',
|
|
|
|
subject: 'testemail',
|
|
|
|
html: '<p>This</p>'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.mail);
|
|
|
|
should.exist(jsonResponse.mail[0].message);
|
|
|
|
should.exist(jsonResponse.mail[0].status);
|
|
|
|
|
|
|
|
jsonResponse.mail[0].status.should.eql({message: 'sent'});
|
|
|
|
jsonResponse.mail[0].message.subject.should.eql('testemail');
|
|
|
|
mailService.GhostMailer.prototype.send.called.should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|