55from rest_framework .reverse import reverse
66from rest_framework .test import APIClient
77
8+ from api .notifications .views import NotificationType
89from webview .models import Notification
910
1011
@@ -13,21 +14,24 @@ def test_list_notifications_authenticated(
1314 user : User ,
1415 make_maintainer_notification : Callable [..., list [Notification ]],
1516) -> None :
16- make_maintainer_notification (user )
17+ db_notifications = make_maintainer_notification (user )
1718
1819 url = reverse ("notification-list" )
1920 response = client .get (url )
2021
2122 assert response .status_code == status .HTTP_200_OK
2223 assert response .data ["count" ] == 1
2324
24- api_data = response .data ["results" ]
25- assert api_data [0 ]["title" ] == (
25+ results = response .data ["results" ]
26+ assert results [0 ]["title" ] == (
2627 "CVE-2025-0001 was automatically matched to packages you subscribed to"
2728 )
28- assert api_data [0 ]["is_read" ] is False
29- assert "id" in api_data [0 ]
30- assert "created_at" in api_data [0 ]
29+ assert results [0 ]["is_read" ] is False
30+ assert "id" in results [0 ]
31+ assert "created_at" in results [0 ]
32+ assert results [0 ]["type" ] == NotificationType .SUGGESTION
33+ assert results [0 ]["message" ] is None
34+ assert results [0 ]["suggestion_id" ] == db_notifications [0 ].suggestion_id
3135
3236
3337def test_list_notifications_are_paginated (
@@ -94,8 +98,11 @@ def test_list_notifications_includes_text_notifications(
9498 assert response .data ["count" ] == 1
9599
96100 api_data = response .data ["results" ]
101+ assert api_data [0 ]["type" ] == NotificationType .TEXT
97102 assert api_data [0 ]["title" ] == "Hello"
98103 assert api_data [0 ]["is_read" ] is False
104+ assert api_data [0 ]["message" ] == "World"
105+ assert api_data [0 ]["suggestion_id" ] is None
99106
100107
101108def test_list_notifications_shows_both_types (
@@ -104,10 +111,28 @@ def test_list_notifications_shows_both_types(
104111 make_maintainer_notification : Callable [..., list [Notification ]],
105112) -> None :
106113 user .profile .create_text_notification ("Hello" , "World" )
107- make_maintainer_notification (user )
114+ db_suggestion_notifications = make_maintainer_notification (user )
108115
109116 url = reverse ("notification-list" )
110117 response = client .get (url )
111118
112119 assert response .status_code == status .HTTP_200_OK
113120 assert response .data ["count" ] == 2
121+
122+ results = response .data ["results" ]
123+ text_result = next (r for r in results if r ["type" ] == NotificationType .TEXT )
124+ suggestion_result = next (
125+ r for r in results if r ["type" ] == NotificationType .SUGGESTION
126+ )
127+
128+ assert text_result ["type" ] == NotificationType .TEXT
129+ assert text_result ["title" ] == "Hello"
130+ assert text_result ["message" ] == "World"
131+ assert text_result ["suggestion_id" ] is None
132+
133+ assert suggestion_result ["type" ] == NotificationType .SUGGESTION
134+ assert (
135+ suggestion_result ["suggestion_id" ]
136+ == db_suggestion_notifications [0 ].suggestion_id
137+ )
138+ assert suggestion_result ["message" ] is None
0 commit comments