Skip to content

Commit

Permalink
Merge pull request #1398 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed Sep 3, 2021
2 parents c414f19 + fceb6aa commit 424dd72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/module/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const plugin = (type, options) => {
return p;
}, {})
: context;
return onRewrite === undefined ? true : wrap(onRewrite)();
return onRewrite === undefined ? true : wrap(onRewrite)({ data });
}
};
return self;
Expand Down
25 changes: 25 additions & 0 deletions test/module/rewriter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,29 @@ describe('Testing rewriter', () => {
expect(data).to.deep.equal([{ idA: [1], idB: [2] }]);
expect(logs).to.deep.equal([1, 2, 2, 1]);
});

it('Testing onRewrite kwargs', () => {
const dataStoreFields = ['id'];
const data = { id: 1 };
const fields = ['name'];
let onRewriteKwargs;
const plugin = injectPlugin({
name: 'inject-plugin-name',
target: 'name',
onRewrite: (kwargs) => {
onRewriteKwargs = Object.keys(kwargs);
return true;
},
fnSchema: (r) => typeof r === 'string',
requires: ['id'],
fn: ({ value }) => `name: ${String(value.id)}`
});
const rew = rewriter({
'': [plugin]
}, dataStoreFields).init(fields);
expect(rew.fieldsToRequest).to.deep.equal(['id']);
rew.rewrite(data);
expect(onRewriteKwargs).to.deep.equal(['data', 'cache', 'context']);
expect(data).to.deep.equal({ name: 'name: 1' });
});
});

0 comments on commit 424dd72

Please sign in to comment.