Commit 2f1e33b
Add tests for auto-store-data.js middleware (#81)
Adds test coverage for the `auto-store-data.js` Express middleware using
Node's native test and assert libraries.
## Test Coverage
- **Session management**: Initialization and preservation of
`req.session.data`
- **Data sources**: POST body and GET query parameters (query overrides
body)
- **Field filtering**: Underscore-prefixed fields are ignored
- **Checkbox handling**: `_unchecked` values delete fields; filtered
from arrays
- **Nested objects**: Recursive merging and object initialization
- **Response locals**: Population of `res.locals.data` from session
## Example Test Pattern
```javascript
describe('autoStoreData middleware', () => {
let req, res, nextCalled
beforeEach(() => {
req = { body: {}, query: {}, session: {} }
res = { locals: {} }
nextCalled = false
})
const next = () => { nextCalled = true }
it('should filter _unchecked from array values', () => {
req.body = { preferences: ['email', '_unchecked', 'sms'] }
autoStoreData(req, res, next)
assert.deepStrictEqual(req.session.data.preferences, ['email', 'sms'])
})
})
```
26 test cases added following the existing test patterns in
`tests/express-middleware/`.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Add tests for `auto-store-data.js`</issue_title>
> <issue_description>These tests should follow the pattern of the
existing ones, and use the Node assert and test
libraries.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #80
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/nhsuk/nhsuk-prototype-kit-package/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: frankieroberto <30665+frankieroberto@users.noreply.github.com>1 parent 9c1df3a commit 2f1e33b
1 file changed
+410
-0
lines changed
0 commit comments