Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Commit cbe9803

Browse files
pass the whole action to the whitelist function
1 parent dcc567c commit cbe9803

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/__tests__/createMiddleware-test.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,38 @@ describe('createMiddleware', () => {
101101
const store = { getState: sinon.spy() };
102102
const next = sinon.spy();
103103
const action = { type: 'ALLOWED' };
104-
const whitelistFn = (type) => {
105-
return type === 'ALLOWED';
106-
};
104+
const whitelistFn = () => true;
107105

108106
createMiddleware(engine, [], whitelistFn)(store)(next)(action);
109107

110108
engine.save.should.have.been.called;
111109
});
112110

111+
it('should ignore actions if the whitelist function returns false', () => {
112+
const engine = { save: sinon.stub().resolves() };
113+
const store = { getState: sinon.spy() };
114+
const next = sinon.spy();
115+
const action = { type: 'ALLOWED' };
116+
const whitelistFn = () => false;
117+
118+
createMiddleware(engine, [], whitelistFn)(store)(next)(action);
119+
120+
engine.save.should.not.have.been.called;
121+
});
122+
123+
it('should pass the whole action to the whitelist function', (done) => {
124+
const engine = { save: sinon.stub().resolves() };
125+
const store = { getState: sinon.spy() };
126+
const next = sinon.spy();
127+
const action = { type: 'ALLOWED' };
128+
const whitelistFn = (checkAction) => {
129+
checkAction.should.deep.equal(action);
130+
done();
131+
};
132+
133+
createMiddleware(engine, [], whitelistFn)(store)(next)(action);
134+
});
135+
113136
describeConsoleWarnInNonProduction(
114137
'should not process functions',
115138
() => {

src/createMiddleware.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ function isValidAction(action) {
5353

5454
function handleWhitelist(action, actionWhitelist) {
5555
if (Array.isArray(actionWhitelist)) {
56-
// Don't filter if the whitelist is empty
57-
return actionWhitelist.length === 0 ? true : actionWhitelist.indexOf(action.type) !== -1;
56+
return actionWhitelist.length === 0
57+
? true // Don't filter if the whitelist is empty
58+
: actionWhitelist.indexOf(action.type) !== -1;
5859
}
60+
5961
// actionWhitelist is a function that returns true or false
60-
return actionWhitelist(action.type);
62+
return actionWhitelist(action);
6163
}
6264

6365
export default (engine, actionBlacklist = [], actionWhitelist = []) => {

0 commit comments

Comments
 (0)