0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added slack controller to v2 API (#10086)

refs #10060

- Added slack controller to v2 admin API
- Added new API test for slack API controller
This commit is contained in:
Rishabh Garg 2018-11-07 03:50:43 +05:30 committed by Naz Gargol
parent ec03b3cfc5
commit 3b8621e19c
4 changed files with 67 additions and 1 deletions

View file

@ -73,5 +73,9 @@ module.exports = {
get oembed() {
return shared.pipeline(require('./oembed'), localUtils);
},
get slack() {
return shared.pipeline(require('./slack'), localUtils);
}
};

View file

@ -0,0 +1,11 @@
const common = require('../../lib/common');
module.exports = {
docName: 'slack',
sendTest: {
permissions: false,
query() {
common.events.emit('slack.test');
}
}
};

View file

@ -151,7 +151,7 @@ module.exports = function apiRoutes() {
router.post('/mail/test', mw.authAdminAPI, apiv2.http(apiv2.mail.sendTest));
// ## Slack
router.post('/slack/test', mw.authAdminAPI, api.http(api.slack.sendTest));
router.post('/slack/test', mw.authAdminAPI, apiv2.http(apiv2.slack.sendTest));
// ## Sessions
router.get('/session', mw.authAdminAPI, api.http(apiv2.session.read));

View file

@ -0,0 +1,51 @@
const should = require('should');
const supertest = require('supertest');
const sinon = require('sinon');
const testUtils = require('../../../../utils');
const localUtils = require('./utils');
const config = require('../../../../../server/config');
const common = require('../../../../../server/lib/common');
const ghost = testUtils.startGhost;
let request;
describe('Slack API', function () {
let ghostServer;
let sandbox;
before(function () {
sandbox = sinon.sandbox.create();
return ghost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
request = supertest.agent(config.get('url'));
})
.then(function () {
return localUtils.doAuth(request);
});
});
after(function () {
sandbox.restore();
});
it('should be able to post slack test', function (done) {
const eventSpy = sandbox.spy(common.events, 'emit');
request.post(localUtils.API.getApiQuery('slack/test/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
eventSpy.calledOnce.should.be.true();
eventSpy.calledWith('slack.test').should.be.true();
done();
});
});
});