|
10 | 10 | from peachjam.models import ( |
11 | 11 | Court, |
12 | 12 | ExtractedCitation, |
| 13 | + Journal, |
| 14 | + JournalArticle, |
13 | 15 | Judgment, |
| 16 | + LawReport, |
| 17 | + LawReportEntry, |
| 18 | + LawReportVolume, |
14 | 19 | Legislation, |
15 | 20 | Locality, |
16 | 21 | Predicate, |
@@ -157,6 +162,84 @@ def test_send_new_documents_email_includes_first_topic_in_subject(self): |
157 | 162 | request = mailer.call_args[0][0] |
158 | 163 | self.assertEqual(f"New documents for {topic}", str(request.subject)) |
159 | 164 |
|
| 165 | + def test_journal_follow_creates_new_documents_timeline_event(self): |
| 166 | + journal = Journal.objects.create( |
| 167 | + title="Regional Law Journal", |
| 168 | + slug="regional-law-journal", |
| 169 | + ) |
| 170 | + follow = UserFollowing.objects.create(user=self.user, journal=journal) |
| 171 | + follow.last_alerted_at = self.last_alerted_at |
| 172 | + follow.save(update_fields=["last_alerted_at"]) |
| 173 | + article = JournalArticle.objects.create( |
| 174 | + title="Fresh journal article", |
| 175 | + journal=journal, |
| 176 | + publisher="Publisher", |
| 177 | + date=datetime(2025, 10, 1), |
| 178 | + language=Language.objects.get(pk="en"), |
| 179 | + jurisdiction=Country.objects.get(pk="ZA"), |
| 180 | + ) |
| 181 | + |
| 182 | + UserFollowing.update_follows_for_user(self.user) |
| 183 | + |
| 184 | + event = TimelineEvent.objects.get(user_following=follow) |
| 185 | + self.assertEqual(TimelineEvent.EventTypes.NEW_DOCUMENTS, event.event_type) |
| 186 | + self.assertIn(article.work, event.subject_works.all()) |
| 187 | + |
| 188 | + def test_law_report_follow_creates_new_documents_timeline_event(self): |
| 189 | + law_report = LawReport.objects.create( |
| 190 | + title="Regional Law Reports", |
| 191 | + slug="regional-law-reports", |
| 192 | + ) |
| 193 | + volume = LawReportVolume.objects.create( |
| 194 | + title="Volume 1", |
| 195 | + slug="volume-1", |
| 196 | + law_report=law_report, |
| 197 | + year=2025, |
| 198 | + ) |
| 199 | + follow = UserFollowing.objects.create(user=self.user, law_report=law_report) |
| 200 | + follow.last_alerted_at = self.last_alerted_at |
| 201 | + follow.save(update_fields=["last_alerted_at"]) |
| 202 | + judgment = Judgment.objects.create( |
| 203 | + case_name="Reported case", |
| 204 | + court=self.court, |
| 205 | + date=datetime(2025, 10, 1), |
| 206 | + language=Language.objects.get(pk="en"), |
| 207 | + jurisdiction=Country.objects.get(pk="ZA"), |
| 208 | + ) |
| 209 | + LawReportEntry.objects.create(judgment=judgment, law_report_volume=volume) |
| 210 | + |
| 211 | + UserFollowing.update_follows_for_user(self.user) |
| 212 | + |
| 213 | + event = TimelineEvent.objects.get(user_following=follow) |
| 214 | + self.assertEqual(TimelineEvent.EventTypes.NEW_DOCUMENTS, event.event_type) |
| 215 | + self.assertIn(judgment.work, event.subject_works.all()) |
| 216 | + |
| 217 | + def test_send_new_documents_email_includes_journal_in_subject(self): |
| 218 | + journal = Journal.objects.create( |
| 219 | + title="Regional Law Journal", |
| 220 | + slug="regional-law-journal", |
| 221 | + ) |
| 222 | + follow = UserFollowing.objects.create(user=self.user, journal=journal) |
| 223 | + doc = Judgment.objects.first() |
| 224 | + TimelineEvent.add_new_documents_event(follow, [doc]) |
| 225 | + |
| 226 | + with ( |
| 227 | + override_settings( |
| 228 | + PEACHJAM={ |
| 229 | + **settings.PEACHJAM, |
| 230 | + "EMAIL_ALERTS_ENABLED": True, |
| 231 | + "CUSTOMERIO_EMAIL_API_KEY": "test", |
| 232 | + }, |
| 233 | + TEMPLATED_EMAIL_BACKEND="peachjam.emails.CustomerIOTemplateBackend", |
| 234 | + ), |
| 235 | + patch("peachjam.emails.APIClient.send_email") as mailer, |
| 236 | + ): |
| 237 | + TimelineEmailService.send_new_documents_email(self.user) |
| 238 | + |
| 239 | + self.assertEqual(1, mailer.call_count) |
| 240 | + request = mailer.call_args[0][0] |
| 241 | + self.assertEqual(f"New documents for {journal}", str(request.subject)) |
| 242 | + |
160 | 243 |
|
161 | 244 | class TimelineRelationshipTests(TestCase): |
162 | 245 | fixtures = [ |
|
0 commit comments