Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow non-Symbol object properties on RSAA #192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,9 @@ A *Redux Standard API-calling Action* MUST
- be a plain JavaScript object,
- have an `[RSAA]` property.

A *Redux Standard API-calling Action* MUST NOT
A *Redux Standard API-calling Action* MAY

- include properties other than `[RSAA]`.
- include properties other than `[RSAA]` (but will be ignored by redux-api-middleware).

#### `[RSAA]`

Expand Down
6 changes: 0 additions & 6 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ function validateRSAA(action) {
return validationErrors;
}

for (let key in action) {
if (key !== RSAA) {
validationErrors.push(`Invalid root key: ${key}`);
}
}

const callAPI = action[RSAA];
if (!isPlainObject(callAPI)) {
validationErrors.push('[RSAA] property must be a plain JavaScript object');
Expand Down
33 changes: 24 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ test('validateRSAA/isValidRSAA must identify conformant RSAAs', t => {
);

const action2 = {
[RSAA]: {},
invalidKey: ''
[RSAA]: {
endpoint: '',
method: 'GET',
types: ['REQUEST', 'SUCCESS', 'FAILURE']
},
anotherKey: 'foo'
};
t.ok(
validateRSAA(action2).includes('Invalid root key: invalidKey'),
'RSAAs must not have properties other than [RSAA] (validateRSAA)'
);
t.notOk(
isValidRSAA(action2),
'RSAAs must not have properties other than [RSAA] (isValidRSAA)'
t.equal(
validateRSAA(action2).length,
0,
'RSAAs may have properties other than [RSAA] (validateRSAA)'
);

const action3 = {
Expand Down Expand Up @@ -565,6 +566,20 @@ test('validateRSAA/isValidRSAA must identify conformant RSAAs', t => {
'[RSAA].ok property must be a function (isRSAA)'
);

const action30 = {
[RSAA]: {
endpoint: '',
method: 'GET',
types: ['REQUEST', 'SUCCESS', 'FAILURE']
},
[Symbol('action30 Symbol')]: 'foo'
};
t.equal(
validateRSAA(action30).length,
0,
'RSAAs may have Symbol properties other than [RSAA] (validateRSAA)'
);

t.end();
});

Expand Down