mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 16:42:17 +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
61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
const errors = require('@tryghost/errors');
|
|
const Promise = require('bluebird');
|
|
const sinon = require('sinon');
|
|
const shared = require('../../../../../core/server/api/shared');
|
|
|
|
describe('Unit: api/shared/validators/handle', function () {
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('input', function () {
|
|
it('no api config passed', function () {
|
|
return shared.validators.handle.input()
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('no api validators passed', function () {
|
|
return shared.validators.handle.input({})
|
|
.then(Promise.reject)
|
|
.catch((err) => {
|
|
(err instanceof errors.IncorrectUsageError).should.be.true();
|
|
});
|
|
});
|
|
|
|
it('ensure validators are called', function () {
|
|
const getStub = sinon.stub();
|
|
const addStub = sinon.stub();
|
|
sinon.stub(shared.validators.input.all, 'all').get(() => {
|
|
return getStub;
|
|
});
|
|
sinon.stub(shared.validators.input.all, 'add').get(() => {
|
|
return addStub;
|
|
});
|
|
|
|
const apiValidators = {
|
|
all: {
|
|
add: sinon.stub().resolves()
|
|
},
|
|
posts: {
|
|
add: sinon.stub().resolves()
|
|
},
|
|
users: {
|
|
add: sinon.stub().resolves()
|
|
}
|
|
};
|
|
|
|
return shared.validators.handle.input({docName: 'posts', method: 'add'}, apiValidators, {context: {}})
|
|
.then(() => {
|
|
getStub.calledOnce.should.be.true();
|
|
addStub.calledOnce.should.be.true();
|
|
apiValidators.all.add.calledOnce.should.be.true();
|
|
apiValidators.posts.add.calledOnce.should.be.true();
|
|
apiValidators.users.add.called.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
});
|