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

[IOCOM-1091] Add a message endpoint to create a new message #349

Merged
merged 5 commits into from
Feb 14, 2024

Conversation

Vangaorth
Copy link
Contributor

Short description

This PR adds a new endpoint to create a new message while the dev-server is running.

List of changes proposed in this pull request

  • message creation in MessagesService
  • message in-memory storage in MessagesDatabase
  • message creation endpoint in MessagesRouter

How to test

Call the POST message endpoint and check that the message is correctly created and retrieved using the messages endpoint

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (d59d4e7) 70.59% compared to head (b25c04a) 70.44%.
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #349      +/-   ##
==========================================
- Coverage   70.59%   70.44%   -0.16%     
==========================================
  Files         141      141              
  Lines        4635     4652      +17     
  Branches      544      544              
==========================================
+ Hits         3272     3277       +5     
- Misses       1362     1374      +12     
  Partials        1        1              
Files Coverage Δ
src/config.ts 96.00% <ø> (ø)
src/features/messages/routers/messagesRouter.ts 57.22% <33.33%> (-0.44%) ⬇️
.../features/messages/persistence/messagesDatabase.ts 90.90% <25.00%> (-4.26%) ⬇️
src/features/messages/services/messagesService.ts 58.01% <36.36%> (-2.32%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 202bab7...b25c04a. Read the comment docs.

Vangaorth added a commit to pagopa/io-app that referenced this pull request Feb 14, 2024
## Short description
This PR fixes a condition where a new message could appear twice in the
messages list.

## List of changes proposed in this pull request
In the Message List component:
- Proper use of focus effect, using React's `useFocusEffect` with proper
dependencies
- Loading of previous messages page (with focus effect) does not trigger
anymore when the component is already refreshing all messages.

Latter is what was causing the bug: two subsequent asynchronous requests
(one for all messages and one for just the new one - the previous page)
where the first retrieved all messages while the second just the new
ones, using the current-but-soon-to-be-outdated starting index
(`minimum_id`).
So, the reload-all request ends, filling the redux state with all new
and old messages. If the previous-page request ends after that, its data
has some duplicates in it (the new messages - since its starting
`minimum_id` was the old one, not the current one received from the last
reload-all) but the reducer puts them in front of the previously
receveid ones from the reload-all, duplicating some of them.

## How to test
You can use the io-dev-api-server code [on this
PR](pagopa/io-dev-api-server#349) to create a
new message.

Do the following in less than 60 seconds (the refresh time): select a
message, create a new one (`POST message` endpoint) and go back to the
message list. Now wait for the 60 seconds to expire and use the
pull-down-to-refresh. On the `main` branch, two duplicated messages
should appear on top of the list. On this branch, there is no duplicate.

Co-authored-by: Alessandro Dell'Oste <[email protected]>
@adelloste
Copy link
Member

adelloste commented Feb 14, 2024

It might be useful to add this api call in the homeDashboard.html, what do you think?

@Vangaorth
Copy link
Contributor Author

It might be useful to add this api call in the homeDashboard.html, what do you think?

Agreed, added

@Vangaorth Vangaorth merged commit c2aafbb into master Feb 14, 2024
6 checks passed
@Vangaorth Vangaorth deleted the IOCOM-1091 branch February 14, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants