Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added slack controller to v2 API (#10086)
refs #10060 - Added slack controller to v2 admin API - Added new API test for slack API controller
- Loading branch information
1 parent
ec03b3c
commit 3b8621e
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const common = require('../../lib/common'); | ||
|
||
module.exports = { | ||
docName: 'slack', | ||
sendTest: { | ||
permissions: false, | ||
query() { | ||
common.events.emit('slack.test'); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); |