Fix race condition, update tests
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
60a51cd047
commit
f21ec80ea2
3 changed files with 15 additions and 10 deletions
|
@ -401,7 +401,8 @@ def handle(%{data: %{"type" => "Join"}} = object, meta) do
|
|||
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
|
||||
end
|
||||
|
||||
if Object.local?(joined_event) and joined_event.data["joinMode"] != "free" do
|
||||
if Object.local?(joined_event) and joined_event.data["joinMode"] != "free" and
|
||||
object.data["actor"] != joined_event.data["actor"] do
|
||||
Utils.update_participation_request_count_in_object(joined_event)
|
||||
end
|
||||
|
||||
|
|
|
@ -380,8 +380,12 @@ def accept_join_request(%User{} = user, %User{ap_id: participant_ap_id} = partic
|
|||
with %Activity{} = join_activity <- Utils.get_existing_join(participant_ap_id, event_id),
|
||||
{:ok, accept_data, _} <- Builder.accept(user, join_activity),
|
||||
{:ok, _activity, _} <- Pipeline.common_pipeline(accept_data, local: true),
|
||||
event <- Object.get_by_ap_id(event_id),
|
||||
{:ok, _} <- Utils.update_participation_request_count_in_object(event) do
|
||||
event <- Object.get_by_ap_id(event_id) do
|
||||
if Object.local?(event) and event.data["joinMode"] != "free" and
|
||||
join_activity.data["actor"] == event.data["actor"] do
|
||||
Utils.update_participation_request_count_in_object(event)
|
||||
end
|
||||
|
||||
{:ok, participant}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -111,7 +111,7 @@ test "GET /api/v1/pleroma/events/:id/participations" do
|
|||
|> get("/api/v1/pleroma/events/#{activity.id}/participations")
|
||||
|
||||
assert response = json_response_and_validate_schema(conn, 200)
|
||||
assert length(response) == 2
|
||||
assert length(response) == 3
|
||||
end
|
||||
|
||||
describe "GET /api/v1/pleroma/events/:id/participation_requests" do
|
||||
|
@ -175,7 +175,7 @@ test "don't display requests if not an author", %{conn: conn} do
|
|||
[user: user, conn: conn]
|
||||
end
|
||||
|
||||
test "joins an event", %{conn: conn} do
|
||||
test "joins an event", %{conn: conn, user: user} do
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
|
@ -193,12 +193,12 @@ test "joins an event", %{conn: conn} do
|
|||
|
||||
assert %{
|
||||
data: %{
|
||||
"participation_count" => 1
|
||||
"participation_count" => 2
|
||||
}
|
||||
} = Object.get_by_ap_id(activity.data["object"])
|
||||
end
|
||||
|
||||
test "can't participate in your own event", %{conn: conn, user: user} do
|
||||
test "can't join your own event", %{conn: conn, user: user} do
|
||||
{:ok, activity} =
|
||||
CommonAPI.event(user, %{
|
||||
name: "test event",
|
||||
|
@ -243,7 +243,7 @@ test "leaves an event", %{conn: conn, user: user} do
|
|||
|
||||
assert %{
|
||||
data: %{
|
||||
"participation_count" => 0
|
||||
"participation_count" => 1
|
||||
}
|
||||
} = Object.get_by_ap_id(activity.data["object"])
|
||||
end
|
||||
|
@ -298,8 +298,8 @@ test "accepts a participation request", %{user: user, conn: conn} do
|
|||
|
||||
assert %{
|
||||
data: %{
|
||||
"participations" => [^ap_id],
|
||||
"participation_count" => 1
|
||||
"participations" => [^ap_id, _],
|
||||
"participation_count" => 2
|
||||
}
|
||||
} = Object.get_by_ap_id(activity.data["object"])
|
||||
|
||||
|
|
Loading…
Reference in a new issue