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

Set flashMessages once per request instead of calling getMessages() ad hoc #7394

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peterhudec
Copy link
Contributor

@peterhudec peterhudec commented Dec 12, 2024

Description of change

This PR changes the way flash messages are made available to Express controllers so that if there are any flash messages set on the response, they will automatically be propagated to Redux state through res.locals.globalProps.

The problem with the current implementation was that flash messages wer read ad hoc with res.locals.getMessages(), which if called twice per request wipes out all messages. This PR replaces res.locals.getMessages() with res.locals.flashMessages, which can be read as many times as needed.

The tests are also much simpler now as the existing tests were only testing whether message content of 'success:with-body' messages was deserialized if it contained valid JSON and kept as is if not, but this functionality was baked into the userLocals middleware and could only be tested through that middleware. No other functionality of the middleware was tested, so I extracted the deserialization into a separate pure function which is trivial to test with no need for any mocks, spies or stubs.

Test instructions

Everything should work as before

instead of calling getMessages() arbitrarily
@peterhudec peterhudec requested a review from a team as a code owner December 12, 2024 11:56
Copy link

cypress bot commented Dec 12, 2024

data-hub-frontend    Run #57928

Run Properties:  status check passed Passed #57928  •  git commit 5f92fb73fc: Set flashMessages once per request
Project data-hub-frontend
Branch Review refactor/flash-messages
Run status status check passed Passed #57928
Run duration 01m 41s
Commit git commit 5f92fb73fc: Set flashMessages once per request
Committer Peter Hudec
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 15
View all changes introduced in this branch ↗︎

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.10%. Comparing base (fe018c9) to head (5f92fb7).

Files with missing lines Patch % Lines
src/middleware/user-locals.js 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7394      +/-   ##
==========================================
+ Coverage   88.01%   88.10%   +0.08%     
==========================================
  Files        1167     1167              
  Lines       18139    18140       +1     
  Branches     5136     5136              
==========================================
+ Hits        15965    15982      +17     
+ Misses       2174     2158      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant