|
15 | 15 | from apps.chat.models import Chatroom
|
16 | 16 | from apps.chat.utils import get_group_name
|
17 | 17 | from apps.notification.consumers import NotificationConsumer
|
18 |
| -from apps.notification.models import GlobalNotification, GlobalNotificationConfirm |
| 18 | +from apps.notification.models import ( |
| 19 | + GlobalNotification, |
| 20 | + GlobalNotificationConfirm, |
| 21 | + RentalNotification, |
| 22 | +) |
19 | 23 | from apps.product.models import Product, ProductImage, RentalHistory
|
20 | 24 | from apps.user.models import Account
|
21 | 25 |
|
@@ -109,6 +113,29 @@ async def test_RentalHistory가_처음_생성될때_알림메시지_테스트(se
|
109 | 113 | self.assertEqual(req_notification["return_date"], rental_history.return_date.isoformat())
|
110 | 114 | self.assertEqual(req_notification["rental_date"], rental_history.rental_date.isoformat())
|
111 | 115 |
|
| 116 | + # 대여 알림이 생성되었는지 테스트 |
| 117 | + self.assertTrue( |
| 118 | + await database_sync_to_async( |
| 119 | + RentalNotification.objects.filter( |
| 120 | + recipient=self.lender, rental_history=rental_history, confirm=False |
| 121 | + ).exists |
| 122 | + )() |
| 123 | + ) |
| 124 | + |
| 125 | + rental_notification = await database_sync_to_async(RentalNotification.objects.get)( |
| 126 | + recipient=self.lender, rental_history=rental_history, confirm=False |
| 127 | + ) |
| 128 | + |
| 129 | + # 알림읽기테스트 |
| 130 | + await communicator2.send_json_to( |
| 131 | + {"command": "rental_notification_confirm", "notification_id": rental_notification.id} |
| 132 | + ) |
| 133 | + updated_confirm = await database_sync_to_async(RentalNotification.objects.get)( |
| 134 | + rental_history=rental_history, recipient=self.lender |
| 135 | + ) |
| 136 | + self.assertFalse(updated_confirm.confirm) |
| 137 | + |
| 138 | + # 소켓 연결 해제 |
112 | 139 | await communicator1.disconnect()
|
113 | 140 | await communicator2.disconnect()
|
114 | 141 |
|
@@ -240,16 +267,16 @@ async def test_모든_사용자에게_공통으로_적용되는_알림_테스트
|
240 | 267 | # 유저1의 알림 읽기 테스트
|
241 | 268 | await communicator1.send_json_to({"command": "global_notification_confirm", "notification_id": notification.id})
|
242 | 269 | user1_confirm_instance = await database_sync_to_async(GlobalNotificationConfirm.objects.get)(
|
243 |
| - notification=notification, user=self.user1, confirm=False |
| 270 | + notification=notification, user=self.user1 |
244 | 271 | )
|
245 | 272 | self.assertFalse(user1_confirm_instance.confirm)
|
246 | 273 |
|
247 | 274 | # 유저2의 알림 읽기 테스트
|
248 | 275 | await communicator1.send_json_to({"command": "global_notification_confirm", "notification_id": notification.id})
|
249 |
| - user1_confirm_instance = await database_sync_to_async(GlobalNotificationConfirm.objects.get)( |
250 |
| - notification=notification, user=self.user1, confirm=False |
| 276 | + user2_confirm_instance = await database_sync_to_async(GlobalNotificationConfirm.objects.get)( |
| 277 | + notification=notification, user=self.user2 |
251 | 278 | )
|
252 |
| - self.assertFalse(user1_confirm_instance.confirm) |
| 279 | + self.assertFalse(user2_confirm_instance.confirm) |
253 | 280 |
|
254 | 281 | # 소켓 정리
|
255 | 282 | await communicator1.disconnect()
|
|
0 commit comments