mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
101 lines
3.4 KiB
JavaScript
101 lines
3.4 KiB
JavaScript
const errors = require('@tryghost/errors');
|
|
const should = require('should');
|
|
const Promise = require('bluebird');
|
|
const sinon = require('sinon');
|
|
const shared = require('../../../../../core/server/api/shared');
|
|
|
|
describe('Unit: api/shared/serializers/handle', function () {
|
|
beforeEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('input', function () {
|
|
it('no api config passed', function () {
|
|
return shared.serializers.handle.input()
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('no api serializers passed', function () {
|
|
return shared.serializers.handle.input({})
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('ensure serializers are called with apiConfig and frame', function () {
|
|
const allStub = sinon.stub();
|
|
sinon.stub(shared.serializers.input.all, 'all').get(() => allStub);
|
|
|
|
const apiSerializers = {
|
|
all: sinon.stub().resolves(),
|
|
posts: {
|
|
all: sinon.stub().resolves(),
|
|
browse: sinon.stub().resolves()
|
|
}
|
|
};
|
|
|
|
const apiConfig = {docName: 'posts', method: 'browse'};
|
|
const frame = {};
|
|
|
|
const stubsToCheck = [
|
|
allStub,
|
|
apiSerializers.all,
|
|
apiSerializers.posts.all,
|
|
apiSerializers.posts.browse
|
|
];
|
|
|
|
return shared.serializers.handle.input(apiConfig, apiSerializers, frame)
|
|
.then(() => {
|
|
stubsToCheck.forEach((stub) => {
|
|
stub.calledOnce.should.be.true();
|
|
should.equal(stub.args[0][0], apiConfig);
|
|
should.equal(stub.args[0][1], frame);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('output', function () {
|
|
it('no models passed', function () {
|
|
return shared.serializers.handle.output(null, {}, {}, {});
|
|
});
|
|
|
|
it('no api config passed', function () {
|
|
return shared.serializers.handle.output([])
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('no api serializers passed', function () {
|
|
return shared.serializers.handle.output([], {})
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('ensure serializers are called', function () {
|
|
const apiSerializers = {
|
|
posts: {
|
|
add: sinon.stub().resolves()
|
|
},
|
|
users: {
|
|
add: sinon.stub().resolves()
|
|
}
|
|
};
|
|
|
|
return shared.serializers.handle.output([], {docName: 'posts', method: 'add'}, apiSerializers, {})
|
|
.then(() => {
|
|
apiSerializers.posts.add.calledOnce.should.be.true();
|
|
apiSerializers.users.add.called.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
});
|