0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/test/unit/api/shared/validators/handle_spec.js
Hannah Wolfe 7f1d3ebc07
Move tests from core to root (#11700)
- 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>
2020-03-30 16:26:47 +01:00

61 lines
2.2 KiB
JavaScript

const should = require('should');
const Promise = require('bluebird');
const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common');
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 common.errors.IncorrectUsageError).should.be.true();
});
});
it('no api validators passed', function () {
return shared.validators.handle.input({})
.then(Promise.reject)
.catch((err) => {
(err instanceof common.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();
});
});
});
});