From d3741511aaed3b25ceea06cb36cd17055e6318a3 Mon Sep 17 00:00:00 2001 From: Daniel Miller Date: Fri, 8 Jun 2018 08:45:32 -0700 Subject: [PATCH] allow non-Symbol object properties on RSAA --- README.md | 4 ++-- src/validation.js | 6 ------ test/index.js | 33 ++++++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c9f271c..54afe9a 100644 --- a/README.md +++ b/README.md @@ -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]` diff --git a/src/validation.js b/src/validation.js index c72c210..145d5fb 100644 --- a/src/validation.js +++ b/src/validation.js @@ -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'); diff --git a/test/index.js b/test/index.js index b4d8414..1eddd61 100644 --- a/test/index.js +++ b/test/index.js @@ -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 = { @@ -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(); });