mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
7f1d3ebc07
- move all test files from core/test to test/ - updated all imports and other references - all code inside of core/ is then application code - tests are correctly at the root level - consistent with other repos/projects Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
85 lines
2.1 KiB
JavaScript
85 lines
2.1 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const shared = require('../../../../core/server/api/shared');
|
|
|
|
describe('Unit: api/shared/http', function () {
|
|
let req;
|
|
let res;
|
|
let next;
|
|
|
|
beforeEach(function () {
|
|
req = sinon.stub();
|
|
res = sinon.stub();
|
|
next = sinon.stub();
|
|
|
|
req.body = {
|
|
a: 'a'
|
|
};
|
|
|
|
res.status = sinon.stub();
|
|
res.json = sinon.stub();
|
|
res.set = sinon.stub();
|
|
res.send = sinon.stub();
|
|
|
|
sinon.stub(shared.headers, 'get').resolves();
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('check options', function () {
|
|
const apiImpl = sinon.stub().resolves();
|
|
shared.http(apiImpl)(req, res, next);
|
|
|
|
Object.keys(apiImpl.args[0][0]).should.eql([
|
|
'original',
|
|
'options',
|
|
'data',
|
|
'user',
|
|
'file',
|
|
'files',
|
|
'apiType'
|
|
]);
|
|
|
|
apiImpl.args[0][0].data.should.eql({a: 'a'});
|
|
apiImpl.args[0][0].options.should.eql({
|
|
context: {
|
|
api_key: null,
|
|
integration: null,
|
|
user: null,
|
|
member: null
|
|
}
|
|
});
|
|
});
|
|
|
|
it('api response is fn', function (done) {
|
|
const response = sinon.stub().callsFake(function (req, res, next) {
|
|
should.exist(req);
|
|
should.exist(res);
|
|
should.exist(next);
|
|
apiImpl.calledOnce.should.be.true();
|
|
res.json.called.should.be.false();
|
|
done();
|
|
});
|
|
|
|
const apiImpl = sinon.stub().resolves(response);
|
|
shared.http(apiImpl)(req, res, next);
|
|
});
|
|
|
|
it('api response is fn', function (done) {
|
|
const apiImpl = sinon.stub().resolves('data');
|
|
|
|
next.callsFake(done);
|
|
|
|
res.json.callsFake(function () {
|
|
shared.headers.get.calledOnce.should.be.true();
|
|
res.status.calledOnce.should.be.true();
|
|
res.send.called.should.be.false();
|
|
done();
|
|
});
|
|
|
|
shared.http(apiImpl)(req, res, next);
|
|
});
|
|
});
|