Skip to content

Commit 9e2601a

Browse files
committed
add claim_submitted and bounty_awarded activities
1 parent fed0f58 commit 9e2601a

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ defmodule Algora.Bounties do
146146
url: source.url
147147
})
148148

149-
case Repo.insert(changeset) do
149+
activity_attrs = %{type: :claim_submitted, notify_users: [user.id]}
150+
151+
case Repo.insert_with_activity(changeset, activity_attrs) do
150152
{:ok, claim} ->
151153
{:ok, claim}
152154

@@ -287,12 +289,18 @@ defmodule Algora.Bounties do
287289
) ::
288290
{:ok, String.t()} | {:error, atom()}
289291
def reward_bounty(%{owner: owner, amount: amount, bounty_id: bounty_id, claims: claims}, opts \\ []) do
290-
create_payment_session(
291-
%{owner: owner, amount: amount, description: "Bounty payment for OSS contributions"},
292-
ticket_ref: opts[:ticket_ref],
293-
bounty_id: bounty_id,
294-
claims: claims
295-
)
292+
Repo.transact(fn ->
293+
activity_attrs = %{type: :bounty_awarded}
294+
295+
with {:ok, _activity} <- Algora.Activities.insert(%Bounty{id: bounty_id}, activity_attrs) do
296+
create_payment_session(
297+
%{owner: owner, amount: amount, description: "Bounty payment for OSS contributions"},
298+
ticket_ref: opts[:ticket_ref],
299+
bounty_id: bounty_id,
300+
claims: claims
301+
)
302+
end
303+
end)
296304
end
297305

298306
@spec generate_line_items(

test/algora/bounties_test.exs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ defmodule Algora.BountiesTest do
6767
installation_id: installation.id
6868
)
6969

70+
claim = Algora.Repo.one(Algora.Bounties.Claim.preload(claim.id))
71+
72+
assert {:ok, _bounty} =
73+
Algora.Bounties.reward_bounty(
74+
%{
75+
owner: owner,
76+
amount: ~M[4000]usd,
77+
bounty_id: bounty.id,
78+
claims: [claim]
79+
},
80+
installation_id: installation.id
81+
)
82+
7083
assert {:ok, _stripe_session_url} =
7184
Algora.Bounties.create_tip(
7285
%{
@@ -79,22 +92,21 @@ defmodule Algora.BountiesTest do
7992
claims: [claim]
8093
)
8194

82-
assert_activity_names([:bounty_posted, :tip_awarded])
83-
assert_activity_names_for_user(creator.id, [:bounty_posted, :tip_awarded])
84-
assert_activity_names_for_user(recipient.id, [:tip_awarded])
95+
assert_activity_names([:bounty_posted, :claim_submitted, :bounty_awarded, :tip_awarded])
96+
assert_activity_names_for_user(creator.id, [:bounty_posted, :bounty_awarded, :tip_awarded])
97+
assert_activity_names_for_user(recipient.id, [:claim_submitted, :tip_awarded])
8598

86-
assert [_activity, activity] = Enum.reverse(Algora.Activities.all())
99+
assert [_bounty, _claim, _awarded, activity] = Enum.reverse(Algora.Activities.all())
87100
assert "tip_activities" == activity.assoc_name
88101
assert activity.notify_users == [recipient.id]
89-
90102
assert activity = Algora.Activities.get_with_preloaded_assoc(activity.assoc_name, activity.id)
91103
assert activity.assoc.__meta__.schema == Algora.Bounties.Tip
92104
assert activity.assoc.creator.id == creator.id
93105
end
94106

95107
test "query" do
96-
[bounty | _] =
97-
Enum.map(1..10, fn _n ->
108+
{:ok, bounty} =
109+
Enum.reduce(1..10, nil, fn _n, _acc ->
98110
creator = insert!(:user)
99111
owner = insert!(:user)
100112
_installation = insert!(:installation, owner: creator)
@@ -111,8 +123,7 @@ defmodule Algora.BountiesTest do
111123
amount: amount
112124
}
113125

114-
{:ok, bounty} = Algora.Bounties.create_bounty(bounty_params, [])
115-
bounty
126+
Algora.Bounties.create_bounty(bounty_params, [])
116127
end)
117128

118129
assert Algora.Bounties.list_bounties(

0 commit comments

Comments
 (0)