Skip to content

Commit

Permalink
Added slack controller to v2 API (#10086)
Browse files Browse the repository at this point in the history
refs #10060

- Added slack controller to v2 admin API
- Added new API test for slack API controller
  • Loading branch information
rishabhgrg authored and naz committed Nov 6, 2018
1 parent ec03b3c commit 3b8621e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/server/api/v2/index.js
Expand Up @@ -73,5 +73,9 @@ module.exports = {

get oembed() {
return shared.pipeline(require('./oembed'), localUtils);
},

get slack() {
return shared.pipeline(require('./slack'), localUtils);
}
};
11 changes: 11 additions & 0 deletions core/server/api/v2/slack.js
@@ -0,0 +1,11 @@
const common = require('../../lib/common');

module.exports = {
docName: 'slack',
sendTest: {
permissions: false,
query() {
common.events.emit('slack.test');
}
}
};
2 changes: 1 addition & 1 deletion core/server/web/api/v2/admin/routes.js
Expand Up @@ -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));
Expand Down
51 changes: 51 additions & 0 deletions core/test/functional/api/v2/admin/slack_spec.js
@@ -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();
});
});
});

0 comments on commit 3b8621e

Please sign in to comment.