Ghost/test/api-acceptance/admin/mail_spec.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-10-12 20:44:05 +03:00
const should = require('should');
const supertest = require('supertest');
const sinon = require('sinon');
const testUtils = require('../../utils');
const config = require('../../../core/shared/config');
const mailService = require('../../../core/server/services/mail');
2018-10-12 20:44:05 +03:00
const localUtils = require('./utils');
describe('Mail API', function () {
let request;
2018-10-12 20:44:05 +03:00
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await localUtils.doAuth(request, 'invites');
2018-10-12 20:44:05 +03:00
});
beforeEach(function () {
sinon.stub(mailService.GhostMailer.prototype, 'send').resolves({message: 'sent'});
2018-10-12 20:44:05 +03:00
});
afterEach(function () {
sinon.restore();
2018-10-12 20:44:05 +03:00
});
it('Can send mail', async function () {
const res = await request
2018-10-12 20:44:05 +03:00
.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);
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
2018-10-12 20:44:05 +03:00
should.exist(jsonResponse);
should.exist(jsonResponse.mail);
should.exist(jsonResponse.mail[0].message);
should.exist(jsonResponse.mail[0].status);
2018-10-12 20:44:05 +03:00
jsonResponse.mail[0].status.should.eql({message: 'sent'});
jsonResponse.mail[0].message.subject.should.eql('testemail');
mailService.GhostMailer.prototype.send.called.should.be.true();
2018-10-12 20:44:05 +03:00
});
});