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

Add notification API tests #5715

Merged
merged 4 commits into from
Jun 8, 2023
Merged

Conversation

d-rita
Copy link
Contributor

@d-rita d-rita commented Apr 18, 2023

This PR adds tests related to the Notifications API endpoints.

Related issue:

How to test:

  • create a test database following the instructions here. The database name is preceded by test_
  • pull and checkout test branch using git fetch origin && git checkout chore/add-notifications-tests
  • run tests using python3 -m unittest discover tests/backend

@d-rita d-rita force-pushed the chore/add-notifications-tests branch 2 times, most recently from e663cad to 9ad0953 Compare April 18, 2023 14:01
@d-rita d-rita mentioned this pull request Apr 19, 2023
17 tasks
@Aadesh-Baral
Copy link
Contributor

@d-rita is this ready for review?

@d-rita
Copy link
Contributor Author

d-rita commented Apr 20, 2023

@d-rita is this ready for review?

@Aadesh-Baral not yet, two failing tests for the get and post unread count api endpoints

@sonarcloud
Copy link

sonarcloud bot commented Apr 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Aadesh-Baral
Copy link
Contributor

@d-rita What's the status of this PR?

@d-rita d-rita force-pushed the chore/add-notifications-tests branch from b400d8d to 76f122f Compare May 31, 2023 15:56
@d-rita
Copy link
Contributor Author

d-rita commented May 31, 2023

@Aadesh-Baral this is ready for review.

  • I have included tests for the query parameters attached to the NotificationsAllApi.
  • I have also updated the message_type filter implementation for a user to enter a string value of the message type, i.e. /api/v2/notifications/?messageType=system

@d-rita d-rita requested a review from Aadesh-Baral May 31, 2023 16:07
Copy link
Contributor

@Aadesh-Baral Aadesh-Baral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases for query param sortBy and sortDirection seems to be missing for NotificationsAllAPI. Other than that LGTM.

Comment on lines 709 to 719
message_type_filters = [
key.strip().lower() for key in message_type.split(",")
]

filter_values = [
key.value
for key in MessageType
if key.name.lower() in message_type_filters
]

query = query.filter(Message.message_type.in_(filter_values))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I could not retrieve any notifications if I specified the message type. Not when I used numbers (for the mapped integer value assigned to a type under the MessageType enum class), e.g. 1 (system), 2 (broadcast)., etc. Nor when I typed in the string value itself, e.g. system/SYSTEM/System. That was with the previous implementation.

So, this new implementation lets a user retrieve the specific messages when they filter by the string value of the message type, e.g. system, mention_notification, broadcast, etc.

Could you test to confirm if my findings were accurate or not? @Aadesh-Baral

Copy link
Contributor

@Aadesh-Baral Aadesh-Baral Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has introduced a problem on the frontend. In our frontend code, we have four notification types that are associated with different combinations of MessageTypes. You can find more information about this issue in the following link: Comment.

For instance, when applying a teams filter in the frontend, a query parameter is passed as "types=6,7,11" in the NotificationsAllAPI. To filter and retrieve the notifications for the provided message types on the backend, this value needs to be split by comma (',') and converted to integers.

However, due to this change, the value is being split correctly but is not being converted to integers, resulting in empty results being returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I have adjusted the tests, removed this change, and added tests for the sortBy and sortDirection query parameters.
Sidenote: For future reference, we should probably include in the documentation the expected values for the message_type filter and what type the respective numerical values correspond to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, we should probably include in the documentation the expected values for the message_type filter and what type the respective numerical values correspond to.

Sounds good

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, we should probably include in the documentation the expected values for the message_type filter and what type the respective numerical values correspond to.

@d-rita Let's do this in this PR itself.

@d-rita d-rita force-pushed the chore/add-notifications-tests branch from 76f122f to aa69d22 Compare June 5, 2023 17:27
@d-rita d-rita requested a review from Aadesh-Baral June 6, 2023 09:14
@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Aadesh-Baral Aadesh-Baral merged commit eead34e into develop Jun 8, 2023
@Aadesh-Baral Aadesh-Baral deleted the chore/add-notifications-tests branch June 8, 2023 04:13
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