Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 8803436

Browse files
committed
refactor(mailbox): read_all test
1 parent 2136175 commit 8803436

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

lib/groupher_server_web/schema/account/account_mutations.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,13 @@ defmodule GroupherServerWeb.Schema.Account.Mutations do
105105
middleware(M.Authorize, :login)
106106
resolve(&R.Accounts.mark_read/3)
107107
end
108+
109+
@desc "mark all unread message as read"
110+
field :mark_read_all, :done do
111+
arg(:type, :mailbox_type, default_value: :mention)
112+
113+
middleware(M.Authorize, :login)
114+
resolve(&R.Accounts.mark_read_all/3)
115+
end
108116
end
109117
end

test/groupher_server_web/mutation/accounts/mailbox_test.exs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do
66
setup do
77
{:ok, user} = db_insert(:user)
88
{:ok, user2} = db_insert(:user)
9+
{:ok, user3} = db_insert(:user)
910

1011
user_conn = simu_conn(:user, user)
1112
guest_conn = simu_conn(:guest)
1213

13-
{:ok, ~m(user_conn guest_conn user user2)a}
14+
{:ok, ~m(user_conn guest_conn user user2 user3)a}
1415
end
1516

1617
describe "[mark_read/all]" do
@@ -52,14 +53,40 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do
5253
assert notify.read
5354
end
5455

55-
test "can mark read all mentions" do
56-
#
57-
true
56+
@query """
57+
mutation($type: MailboxType) {
58+
markReadAll(type: $type) {
59+
done
60+
}
61+
}
62+
"""
63+
@tag :wip
64+
test "can mark read all mentions", ~m(user_conn user user2 user3)a do
65+
{:ok, _} = mock_mention_for(user, user2)
66+
{:ok, _} = mock_mention_for(user, user3)
67+
68+
{:ok, mentions} = Delivery.fetch(:mention, user, %{page: 1, size: 10})
69+
assert mentions.total_count == 2
70+
71+
variables = %{type: "MENTION"}
72+
result = user_conn |> mutation_result(@query, variables, "markReadAll")
73+
74+
{:ok, mentions} = Delivery.fetch(:mention, user, %{page: 1, size: 10, read: true})
75+
assert mentions.total_count == 2
5876
end
5977

60-
test "can mark read all notifications" do
61-
#
62-
true
78+
@tag :wip
79+
test "can mark read all notifications", ~m(user_conn user user2)a do
80+
{:ok, _} = mock_notification_for(user, user2)
81+
82+
{:ok, notifications} = Delivery.fetch(:notification, user, %{page: 1, size: 10})
83+
assert notifications.total_count == 1
84+
85+
variables = %{type: "NOTIFICATION"}
86+
result = user_conn |> mutation_result(@query, variables, "markReadAll")
87+
88+
{:ok, notifications} = Delivery.fetch(:notification, user, %{page: 1, size: 10, read: true})
89+
assert notifications.total_count == 1
6390
end
6491
end
6592

0 commit comments

Comments
 (0)