Stream follow updates
[akkoma] / test / pleroma / web / mastodon_api / controllers / notification_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.Notification
9 alias Pleroma.Repo
10 alias Pleroma.User
11 alias Pleroma.Web.CommonAPI
12
13 import Pleroma.Factory
14
15 test "does NOT render account/pleroma/relationship by default" do
16 %{user: user, conn: conn} = oauth_access(["read:notifications"])
17 other_user = insert(:user)
18
19 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
20 {:ok, [_notification]} = Notification.create_notifications(activity)
21
22 response =
23 conn
24 |> assign(:user, user)
25 |> get("/api/v1/notifications")
26 |> json_response_and_validate_schema(200)
27
28 assert Enum.all?(response, fn n ->
29 get_in(n, ["account", "pleroma", "relationship"]) == %{}
30 end)
31 end
32
33 test "list of notifications" do
34 %{user: user, conn: conn} = oauth_access(["read:notifications"])
35 other_user = insert(:user)
36
37 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
38
39 {:ok, [_notification]} = Notification.create_notifications(activity)
40
41 conn =
42 conn
43 |> assign(:user, user)
44 |> get("/api/v1/notifications")
45
46 expected_response =
47 "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
48 user.ap_id
49 }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
50
51 assert [%{"status" => %{"content" => response}} | _rest] =
52 json_response_and_validate_schema(conn, 200)
53
54 assert response == expected_response
55 end
56
57 test "by default, does not contain pleroma:chat_mention" do
58 %{user: user, conn: conn} = oauth_access(["read:notifications"])
59 other_user = insert(:user)
60
61 {:ok, _activity} = CommonAPI.post_chat_message(other_user, user, "hey")
62
63 result =
64 conn
65 |> get("/api/v1/notifications")
66 |> json_response_and_validate_schema(200)
67
68 assert [] == result
69
70 result =
71 conn
72 |> get("/api/v1/notifications?include_types[]=pleroma:chat_mention")
73 |> json_response_and_validate_schema(200)
74
75 assert [_] = result
76 end
77
78 test "by default, does not contain pleroma:report" do
79 %{user: user, conn: conn} = oauth_access(["read:notifications"])
80 other_user = insert(:user)
81 third_user = insert(:user)
82
83 user
84 |> User.admin_api_update(%{is_moderator: true})
85
86 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
87
88 {:ok, _report} =
89 CommonAPI.report(third_user, %{account_id: other_user.id, status_ids: [activity.id]})
90
91 result =
92 conn
93 |> get("/api/v1/notifications")
94 |> json_response_and_validate_schema(200)
95
96 assert [] == result
97
98 result =
99 conn
100 |> get("/api/v1/notifications?include_types[]=pleroma:report")
101 |> json_response_and_validate_schema(200)
102
103 assert [_] = result
104 end
105
106 test "getting a single notification" do
107 %{user: user, conn: conn} = oauth_access(["read:notifications"])
108 other_user = insert(:user)
109
110 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
111
112 {:ok, [notification]} = Notification.create_notifications(activity)
113
114 conn = get(conn, "/api/v1/notifications/#{notification.id}")
115
116 expected_response =
117 "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
118 user.ap_id
119 }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
120
121 assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
122 assert response == expected_response
123 end
124
125 test "dismissing a single notification (deprecated endpoint)" do
126 %{user: user, conn: conn} = oauth_access(["write:notifications"])
127 other_user = insert(:user)
128
129 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
130
131 {:ok, [notification]} = Notification.create_notifications(activity)
132
133 conn =
134 conn
135 |> assign(:user, user)
136 |> put_req_header("content-type", "application/json")
137 |> post("/api/v1/notifications/dismiss", %{"id" => to_string(notification.id)})
138
139 assert %{} = json_response_and_validate_schema(conn, 200)
140 end
141
142 test "dismissing a single notification" do
143 %{user: user, conn: conn} = oauth_access(["write:notifications"])
144 other_user = insert(:user)
145
146 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
147
148 {:ok, [notification]} = Notification.create_notifications(activity)
149
150 conn =
151 conn
152 |> assign(:user, user)
153 |> post("/api/v1/notifications/#{notification.id}/dismiss")
154
155 assert %{} = json_response_and_validate_schema(conn, 200)
156 end
157
158 test "clearing all notifications" do
159 %{user: user, conn: conn} = oauth_access(["write:notifications", "read:notifications"])
160 other_user = insert(:user)
161
162 {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
163
164 {:ok, [_notification]} = Notification.create_notifications(activity)
165
166 ret_conn = post(conn, "/api/v1/notifications/clear")
167
168 assert %{} = json_response_and_validate_schema(ret_conn, 200)
169
170 ret_conn = get(conn, "/api/v1/notifications")
171
172 assert all = json_response_and_validate_schema(ret_conn, 200)
173 assert all == []
174 end
175
176 test "paginates notifications using min_id, since_id, max_id, and limit" do
177 %{user: user, conn: conn} = oauth_access(["read:notifications"])
178 other_user = insert(:user)
179
180 {:ok, activity1} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
181 {:ok, activity2} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
182 {:ok, activity3} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
183 {:ok, activity4} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
184
185 notification1_id = get_notification_id_by_activity(activity1)
186 notification2_id = get_notification_id_by_activity(activity2)
187 notification3_id = get_notification_id_by_activity(activity3)
188 notification4_id = get_notification_id_by_activity(activity4)
189
190 conn = assign(conn, :user, user)
191
192 # min_id
193 result =
194 conn
195 |> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
196 |> json_response_and_validate_schema(:ok)
197
198 assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
199
200 # since_id
201 result =
202 conn
203 |> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
204 |> json_response_and_validate_schema(:ok)
205
206 assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
207
208 # max_id
209 result =
210 conn
211 |> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
212 |> json_response_and_validate_schema(:ok)
213
214 assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
215 end
216
217 describe "exclude_visibilities" do
218 test "filters notifications for mentions" do
219 %{user: user, conn: conn} = oauth_access(["read:notifications"])
220 other_user = insert(:user)
221
222 {:ok, public_activity} =
223 CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "public"})
224
225 {:ok, direct_activity} =
226 CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})
227
228 {:ok, unlisted_activity} =
229 CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "unlisted"})
230
231 {:ok, private_activity} =
232 CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "private"})
233
234 query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "private"]})
235 conn_res = get(conn, "/api/v1/notifications?" <> query)
236
237 assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
238 assert id == direct_activity.id
239
240 query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "direct"]})
241 conn_res = get(conn, "/api/v1/notifications?" <> query)
242
243 assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
244 assert id == private_activity.id
245
246 query = params_to_query(%{exclude_visibilities: ["public", "private", "direct"]})
247 conn_res = get(conn, "/api/v1/notifications?" <> query)
248
249 assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
250 assert id == unlisted_activity.id
251
252 query = params_to_query(%{exclude_visibilities: ["unlisted", "private", "direct"]})
253 conn_res = get(conn, "/api/v1/notifications?" <> query)
254
255 assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
256 assert id == public_activity.id
257 end
258
259 test "filters notifications for Like activities" do
260 user = insert(:user)
261 %{user: other_user, conn: conn} = oauth_access(["read:notifications"])
262
263 {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})
264
265 {:ok, direct_activity} =
266 CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})
267
268 {:ok, unlisted_activity} =
269 CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})
270
271 {:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"})
272
273 {:ok, _} = CommonAPI.favorite(user, public_activity.id)
274 {:ok, _} = CommonAPI.favorite(user, direct_activity.id)
275 {:ok, _} = CommonAPI.favorite(user, unlisted_activity.id)
276 {:ok, _} = CommonAPI.favorite(user, private_activity.id)
277
278 activity_ids =
279 conn
280 |> get("/api/v1/notifications?exclude_visibilities[]=direct")
281 |> json_response_and_validate_schema(200)
282 |> Enum.map(& &1["status"]["id"])
283
284 assert public_activity.id in activity_ids
285 assert unlisted_activity.id in activity_ids
286 assert private_activity.id in activity_ids
287 refute direct_activity.id in activity_ids
288
289 activity_ids =
290 conn
291 |> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
292 |> json_response_and_validate_schema(200)
293 |> Enum.map(& &1["status"]["id"])
294
295 assert public_activity.id in activity_ids
296 refute unlisted_activity.id in activity_ids
297 assert private_activity.id in activity_ids
298 assert direct_activity.id in activity_ids
299
300 activity_ids =
301 conn
302 |> get("/api/v1/notifications?exclude_visibilities[]=private")
303 |> json_response_and_validate_schema(200)
304 |> Enum.map(& &1["status"]["id"])
305
306 assert public_activity.id in activity_ids
307 assert unlisted_activity.id in activity_ids
308 refute private_activity.id in activity_ids
309 assert direct_activity.id in activity_ids
310
311 activity_ids =
312 conn
313 |> get("/api/v1/notifications?exclude_visibilities[]=public")
314 |> json_response_and_validate_schema(200)
315 |> Enum.map(& &1["status"]["id"])
316
317 refute public_activity.id in activity_ids
318 assert unlisted_activity.id in activity_ids
319 assert private_activity.id in activity_ids
320 assert direct_activity.id in activity_ids
321 end
322
323 test "filters notifications for Announce activities" do
324 user = insert(:user)
325 %{user: other_user, conn: conn} = oauth_access(["read:notifications"])
326
327 {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})
328
329 {:ok, unlisted_activity} =
330 CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})
331
332 {:ok, _} = CommonAPI.repeat(public_activity.id, user)
333 {:ok, _} = CommonAPI.repeat(unlisted_activity.id, user)
334
335 activity_ids =
336 conn
337 |> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
338 |> json_response_and_validate_schema(200)
339 |> Enum.map(& &1["status"]["id"])
340
341 assert public_activity.id in activity_ids
342 refute unlisted_activity.id in activity_ids
343 end
344
345 test "doesn't return less than the requested amount of records when the user's reply is liked" do
346 user = insert(:user)
347 %{user: other_user, conn: conn} = oauth_access(["read:notifications"])
348
349 {:ok, mention} =
350 CommonAPI.post(user, %{status: "@#{other_user.nickname}", visibility: "public"})
351
352 {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
353
354 {:ok, reply} =
355 CommonAPI.post(other_user, %{
356 status: ".",
357 visibility: "public",
358 in_reply_to_status_id: activity.id
359 })
360
361 {:ok, _favorite} = CommonAPI.favorite(user, reply.id)
362
363 activity_ids =
364 conn
365 |> get("/api/v1/notifications?exclude_visibilities[]=direct&limit=2")
366 |> json_response_and_validate_schema(200)
367 |> Enum.map(& &1["status"]["id"])
368
369 assert [reply.id, mention.id] == activity_ids
370 end
371 end
372
373 test "filters notifications using exclude_types" do
374 %{user: user, conn: conn} = oauth_access(["read:notifications"])
375 other_user = insert(:user)
376
377 {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
378 {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
379 {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
380 {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
381 {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
382
383 mention_notification_id = get_notification_id_by_activity(mention_activity)
384 favorite_notification_id = get_notification_id_by_activity(favorite_activity)
385 reblog_notification_id = get_notification_id_by_activity(reblog_activity)
386 follow_notification_id = get_notification_id_by_activity(follow_activity)
387
388 query = params_to_query(%{exclude_types: ["mention", "favourite", "reblog"]})
389 conn_res = get(conn, "/api/v1/notifications?" <> query)
390
391 assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
392
393 query = params_to_query(%{exclude_types: ["favourite", "reblog", "follow"]})
394 conn_res = get(conn, "/api/v1/notifications?" <> query)
395
396 assert [%{"id" => ^mention_notification_id}] =
397 json_response_and_validate_schema(conn_res, 200)
398
399 query = params_to_query(%{exclude_types: ["reblog", "follow", "mention"]})
400 conn_res = get(conn, "/api/v1/notifications?" <> query)
401
402 assert [%{"id" => ^favorite_notification_id}] =
403 json_response_and_validate_schema(conn_res, 200)
404
405 query = params_to_query(%{exclude_types: ["follow", "mention", "favourite"]})
406 conn_res = get(conn, "/api/v1/notifications?" <> query)
407
408 assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
409 end
410
411 test "filters notifications using include_types" do
412 %{user: user, conn: conn} = oauth_access(["read:notifications"])
413 other_user = insert(:user)
414
415 {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
416 {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
417 {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
418 {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
419 {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
420
421 mention_notification_id = get_notification_id_by_activity(mention_activity)
422 favorite_notification_id = get_notification_id_by_activity(favorite_activity)
423 reblog_notification_id = get_notification_id_by_activity(reblog_activity)
424 follow_notification_id = get_notification_id_by_activity(follow_activity)
425
426 conn_res = get(conn, "/api/v1/notifications?include_types[]=follow")
427
428 assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
429
430 conn_res = get(conn, "/api/v1/notifications?include_types[]=mention")
431
432 assert [%{"id" => ^mention_notification_id}] =
433 json_response_and_validate_schema(conn_res, 200)
434
435 conn_res = get(conn, "/api/v1/notifications?include_types[]=favourite")
436
437 assert [%{"id" => ^favorite_notification_id}] =
438 json_response_and_validate_schema(conn_res, 200)
439
440 conn_res = get(conn, "/api/v1/notifications?include_types[]=reblog")
441
442 assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
443
444 result = conn |> get("/api/v1/notifications") |> json_response_and_validate_schema(200)
445
446 assert length(result) == 4
447
448 query = params_to_query(%{include_types: ["follow", "mention", "favourite", "reblog"]})
449
450 result =
451 conn
452 |> get("/api/v1/notifications?" <> query)
453 |> json_response_and_validate_schema(200)
454
455 assert length(result) == 4
456 end
457
458 test "destroy multiple" do
459 %{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
460 other_user = insert(:user)
461
462 {:ok, activity1} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
463 {:ok, activity2} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
464 {:ok, activity3} = CommonAPI.post(user, %{status: "hi @#{other_user.nickname}"})
465 {:ok, activity4} = CommonAPI.post(user, %{status: "hi @#{other_user.nickname}"})
466
467 notification1_id = get_notification_id_by_activity(activity1)
468 notification2_id = get_notification_id_by_activity(activity2)
469 notification3_id = get_notification_id_by_activity(activity3)
470 notification4_id = get_notification_id_by_activity(activity4)
471
472 result =
473 conn
474 |> get("/api/v1/notifications")
475 |> json_response_and_validate_schema(:ok)
476
477 assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
478
479 conn2 =
480 conn
481 |> assign(:user, other_user)
482 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:notifications"]))
483
484 result =
485 conn2
486 |> get("/api/v1/notifications")
487 |> json_response_and_validate_schema(:ok)
488
489 assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
490
491 query = params_to_query(%{ids: [notification1_id, notification2_id]})
492 conn_destroy = delete(conn, "/api/v1/notifications/destroy_multiple?" <> query)
493
494 assert json_response_and_validate_schema(conn_destroy, 200) == %{}
495
496 result =
497 conn2
498 |> get("/api/v1/notifications")
499 |> json_response_and_validate_schema(:ok)
500
501 assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
502 end
503
504 test "doesn't see notifications after muting user with notifications" do
505 %{user: user, conn: conn} = oauth_access(["read:notifications"])
506 user2 = insert(:user)
507
508 {:ok, _, _, _} = CommonAPI.follow(user, user2)
509 {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
510
511 ret_conn = get(conn, "/api/v1/notifications")
512
513 assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
514
515 {:ok, _user_relationships} = User.mute(user, user2)
516
517 conn = get(conn, "/api/v1/notifications")
518
519 assert json_response_and_validate_schema(conn, 200) == []
520 end
521
522 test "see notifications after muting user without notifications" do
523 %{user: user, conn: conn} = oauth_access(["read:notifications"])
524 user2 = insert(:user)
525
526 {:ok, _, _, _} = CommonAPI.follow(user, user2)
527 {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
528
529 ret_conn = get(conn, "/api/v1/notifications")
530
531 assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
532
533 {:ok, _user_relationships} = User.mute(user, user2, %{notifications: false})
534
535 conn = get(conn, "/api/v1/notifications")
536
537 assert length(json_response_and_validate_schema(conn, 200)) == 1
538 end
539
540 test "see notifications after muting user with notifications and with_muted parameter" do
541 %{user: user, conn: conn} = oauth_access(["read:notifications"])
542 user2 = insert(:user)
543
544 {:ok, _, _, _} = CommonAPI.follow(user, user2)
545 {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
546
547 ret_conn = get(conn, "/api/v1/notifications")
548
549 assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
550
551 {:ok, _user_relationships} = User.mute(user, user2)
552
553 conn = get(conn, "/api/v1/notifications?with_muted=true")
554
555 assert length(json_response_and_validate_schema(conn, 200)) == 1
556 end
557
558 @tag capture_log: true
559 test "see move notifications" do
560 old_user = insert(:user)
561 new_user = insert(:user, also_known_as: [old_user.ap_id])
562 %{user: follower, conn: conn} = oauth_access(["read:notifications"])
563
564 old_user_url = old_user.ap_id
565
566 body =
567 File.read!("test/fixtures/users_mock/localhost.json")
568 |> String.replace("{{nickname}}", old_user.nickname)
569 |> Jason.encode!()
570
571 Tesla.Mock.mock(fn
572 %{method: :get, url: ^old_user_url} ->
573 %Tesla.Env{status: 200, body: body}
574 end)
575
576 User.follow(follower, old_user)
577 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
578 Pleroma.Tests.ObanHelpers.perform_all()
579
580 conn = get(conn, "/api/v1/notifications")
581
582 assert length(json_response_and_validate_schema(conn, 200)) == 1
583 end
584
585 describe "link headers" do
586 test "preserves parameters in link headers" do
587 %{user: user, conn: conn} = oauth_access(["read:notifications"])
588 other_user = insert(:user)
589
590 {:ok, activity1} =
591 CommonAPI.post(other_user, %{
592 status: "hi @#{user.nickname}",
593 visibility: "public"
594 })
595
596 {:ok, activity2} =
597 CommonAPI.post(other_user, %{
598 status: "hi @#{user.nickname}",
599 visibility: "public"
600 })
601
602 notification1 = Repo.get_by(Notification, activity_id: activity1.id)
603 notification2 = Repo.get_by(Notification, activity_id: activity2.id)
604
605 conn =
606 conn
607 |> assign(:user, user)
608 |> get("/api/v1/notifications?limit=5")
609
610 assert [link_header] = get_resp_header(conn, "link")
611 assert link_header =~ ~r/limit=5/
612 assert link_header =~ ~r/min_id=#{notification2.id}/
613 assert link_header =~ ~r/max_id=#{notification1.id}/
614 end
615 end
616
617 describe "from specified user" do
618 test "account_id" do
619 %{user: user, conn: conn} = oauth_access(["read:notifications"])
620
621 %{id: account_id} = other_user1 = insert(:user)
622 other_user2 = insert(:user)
623
624 {:ok, _activity} = CommonAPI.post(other_user1, %{status: "hi @#{user.nickname}"})
625 {:ok, _activity} = CommonAPI.post(other_user2, %{status: "bye @#{user.nickname}"})
626
627 assert [%{"account" => %{"id" => ^account_id}}] =
628 conn
629 |> assign(:user, user)
630 |> get("/api/v1/notifications?account_id=#{account_id}")
631 |> json_response_and_validate_schema(200)
632
633 assert %{"error" => "Account is not found"} =
634 conn
635 |> assign(:user, user)
636 |> get("/api/v1/notifications?account_id=cofe")
637 |> json_response_and_validate_schema(404)
638 end
639 end
640
641 defp get_notification_id_by_activity(%{id: id}) do
642 Notification
643 |> Repo.get_by(activity_id: id)
644 |> Map.get(:id)
645 |> to_string()
646 end
647
648 defp params_to_query(%{} = params) do
649 Enum.map_join(params, "&", fn
650 {k, v} when is_list(v) -> Enum.map_join(v, "&", &"#{k}[]=#{&1}")
651 {k, v} -> k <> "=" <> v
652 end)
653 end
654 end