git diff origin/develop -- reducers/authentication.test.jsdraft43npm on fork marked with ⚡. Code may not be available on GitHub until the PR merge.
unknown action → unknown action returns current state. Explicit description: 'reducer doesn't know this action → returns current state unchanged'. The old test didn't say what it was actually verifying.
Input state change: old test checked { loading: true, loggedIn: false }, new one — { loading: false, user: { name: 'test' } }. Chose a logged-in user state to verify that user is not nulled on unknown action — guarantee of a pure function [Redux reducers].
Formatting: old call split across 3 lines, new one — single line. Style only.
Object.freeze(state) [MDN] — mutation protection: if the reducer modifies the passed state (violating purity), the test will fail with an error.
describe('handles USER_LOGIN_BEGIN') → describe('USER_LOGIN_BEGIN'). Removed the word handles — in the new style, all describe blocks are named after the action literally. [new file]⚡
2 of 3 tests deleted.
«fresh state» — verified transition from { loading: false, error: null, ... } → { loading: true, error: null, ... }. [line 34]
«error state» — verified transition from { loading: false, error: exampleError, ... } → { loading: true, error: null, ... }. [line 53]
Both tests verify the same thing: error is nulled, loading becomes true. The difference — in the original error (null vs line). Redundant — one test covers both cases.
«loggedIn state» — input: { loading: false, error: null, loggedIn: false } — completely matches 'fresh state'. Possibly a typo (should have been loggedIn: true). [line 72]
One new test: 'resets to loading with null user' [new file]⚡
{ loading: false, error: 'some error', user: { name: 'old' } }{ loading: true, error: null, user: null }user is nulled (stricter than loggedIn: false — full reset)error is nulled, loading becomes true — as in the old testsloggedIn: false to user: null — key state shape differenceOld test «loading state» — WITHOUT PAYLOAD.
Called { type: 'USER_LOGIN_SUCCESS' } without the third argument (payload). The old reducer supposedly just set loggedIn: true u loading: false — user data was not saved.
Deleted «weird state»: { loading: false, error: exampleError, loggedIn: true } — nonsensical combination: error present with loggedIn = true. [line 115]
New test — with actual payload:
Why these exact fields: the reducer at authentication.js:18-27 expects four payload fields — each written directly to state:
| Payload field | → state field | Line | Purpose |
|---|---|---|---|
payload.user | → state.user | L23 | user object (name, admin?) |
payload.version | → state.version | L24 | build version |
payload.buildTimestamp | → state.buildTimestamp | L25 | when built |
payload.alertMessage | → state.alertMessage | L26 | system message (MOTD) |
The old test passed no payload at all — so it verified none of these fields. The new test checks full correspondence.
loggedIn: true → user: { name: 'testuser' }. Components check state.user !== null instead of state.loggedIn === true — part of the migration to react-redux hooks.
Similar changes: handles USER_LOGIN_FAILURE → USER_LOGIN_FAILURE, 'weird state' deleted, one test instead of two.
New description: 'sets error and clears user/loading' — explicitly states what happens: error stored, user reset, spinner removed.
loggedIn: false → user: null. The user field becomes null on error. This is stricter than loggedIn: false — the old approach kept user data in state (just marked as not logged in), the new one fully clears it. Cofromesponds case USER_LOGIN_FAILURE: user: null.
Formatting payload: { error: exampleError } to one line instead of three. Style only.
Deleted entirely (2 tests, ~40 lines).
Verified that USER_LOGOUT resets { loggedIn: true } b { loggedIn: false } u nulls the error.
Why deleted:
USER_LOGOUT no longer exists — not exported from authentication.js (imports only USER_LOGIN_BEGIN, USER_LOGIN_FAILURE, USER_LOGIN_SUCCESS).USER_LOGOUT not in the reducer switch [only 3 case].USER_LOGIN_BEGIN — both reset the state.USER_LOGOUT from a nonexistent export — the test was broken.Historically: USER_LOGOUT was removed from the source commit 7c60c2fbb (2019-07-13, «implemented logout check») — from actions/authentication.js and from the reducer. But the test was not updated — it continued importing and testing USER_LOGOUT for 7 more years. In the new reducer, logout is simply USER_LOGIN_BEGIN (reset to loading).
(state, action) → new state. No side effects, no mutations. Object.freeze(state) in the test guarantees this: if the reducer accidentally mutates the passed state, the test fails. [Redux docs]{ loading, error, loggedIn }. New: { loading, error, user }. loggedIn: boolean only said "yes/no". user: object|null provides the full user object (id, name, locale, ...) — components get all data at once via useSelector(state => state.authentication.user).Object.freeze(state); reducer(state, action); — if the reducer tries to mutate the state (instead of creating a new one), JavaScript throws an error in strict mode. This verifies function purity. [MDN]| Aspect | Old file (216 lines) | New file (98 lines) |
|---|---|---|
| State shape | { loading, error, loggedIn } |
{ loading, error, user } |
| Initial state | Embedded in test, loading: false |
Constant, matches reducer, loading: true |
| Number of describe | 5 (with prefix handles) |
3 (without prefix) |
| Number of tests | 9 | 4 |
| USER_LOGIN_BEGIN | 3 tests (fresh, error, loggedIn — duplicates) | 1 test (resets to loading) |
| USER_LOGIN_SUCCESS | 2 tests — without payload | 1 test — with payload (user, version, etc.) |
| USER_LOGIN_FAILURE | 2 tests (loading, weird) | 1 test (sets error) |
| USER_LOGOUT | 2 test | Fully deleted — action does not exist |
| Unknown action description | 'unknown action' — unclear |
'unknown action returns current state' — clear |
USER_LOGIN_BEGIN (both reset the state). Action does not exist in the reducer.user, version, buildTimestamp, alertMessage), the new one checks all fields.loggedIn: boolean replaced with user: object|null as part of the migration connect() → useSelector [react-redux hooks].⚡ — link to code b branch draft43npm on fork, not merged into develop. Code may not be available on GitHub until the PR is merged.
1.
initialStateextracted as a constant.Before: object was hardcoded in the test
it('initial state')as{ loading: false, error: null, loggedIn: false }.After: the constant
initialState, kfromwhich k matches cinitialStatefrom the reducer itself [reducers/authentication.js:3].2.
loading: false→loading: true.Old init:
loading: false— user not logged in, no spinner.New init:
loading: true— on app load,loadUserStatus()runs immediately to check the session. Initial state — 'looking for user'. This reducer change commit 8b3b44be7 (2020-03-18).3.
loggedIn: false→user: null. MAIN STATE SHAPE CHANGE.{ loading: boolean, error: string|null, loggedIn: boolean }
{ loading: boolean, error: string|null, user: object|null }
loggedIn: trueafter login → nowuser: { name: 'test', ... }loggedIn: falsebefore login → nowuser: nulluser !== nullinstead ofloggedIn === trueconnect()→useSelector[react-redux hooks]