Added apiImpl.data to apiOptions for serialisation (#10016)

no-issue

This is to give serializers access to the expected data properties so
that can be used for filtering.
This commit is contained in:
Fabien O'Carroll 2018-10-16 16:51:50 +07:00 committed by GitHub
parent 51dde1e38c
commit 2fbc5aa257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -32,7 +32,11 @@ const STAGES = {
serialisation: { serialisation: {
input(apiUtils, apiConfig, apiImpl, frame) { input(apiUtils, apiConfig, apiImpl, frame) {
debug('stages: input serialisation'); debug('stages: input serialisation');
return shared.serializers.handle.input(apiConfig, apiUtils.serializers.input, frame); return shared.serializers.handle.input(
Object.assign({data: apiImpl.data}, apiConfig),
apiUtils.serializers.input,
frame
);
}, },
output(response, apiUtils, apiConfig, apiImpl, frame) { output(response, apiUtils, apiConfig, apiImpl, frame) {
debug('stages: output serialisation'); debug('stages: output serialisation');

View File

@ -27,10 +27,10 @@ describe('Unit: api/shared/serializers/handle', function () {
}); });
}); });
it('ensure serializers are called', function () { it('ensure serializers are called with apiConfig and frame', function () {
const getStub = sandbox.stub(); const allStub = sandbox.stub();
const addStub = sandbox.stub(); const addStub = sandbox.stub();
sandbox.stub(shared.serializers.input.all, 'all').get(() => getStub); sandbox.stub(shared.serializers.input.all, 'all').get(() => allStub);
sandbox.stub(shared.serializers.input.all, 'add').get(() => addStub); sandbox.stub(shared.serializers.input.all, 'add').get(() => addStub);
const apiSerializers = { const apiSerializers = {
@ -41,13 +41,24 @@ describe('Unit: api/shared/serializers/handle', function () {
} }
}; };
return shared.serializers.handle.input({docName: 'posts', method: 'add'}, apiSerializers, {}) const apiConfig = {docName: 'posts', method: 'add'};
const frame = {};
const stubsToCheck = [
allStub,
addStub,
apiSerializers.all,
apiSerializers.posts.all,
apiSerializers.posts.add
];
return shared.serializers.handle.input(apiConfig, apiSerializers, frame)
.then(() => { .then(() => {
getStub.calledOnce.should.be.true(); stubsToCheck.forEach((stub) => {
addStub.calledOnce.should.be.true(); stub.calledOnce.should.be.true();
apiSerializers.all.calledOnce.should.be.true(); should.equal(stub.args[0][0], apiConfig);
apiSerializers.posts.all.calledOnce.should.be.true(); should.equal(stub.args[0][1], frame);
apiSerializers.posts.add.calledOnce.should.be.true(); });
}); });
}); });
}); });