Add more tests

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-10-05 22:45:20 +02:00
parent e187aff5dd
commit 678b6ce17c
6 changed files with 133 additions and 4 deletions

View file

@ -707,7 +707,8 @@ def get_quote(%{data: %{"object" => _object}} = activity, _) do
end
end
def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
def render_content(%{data: %{"name" => name, "type" => type}} = object)
when not is_nil(name) and name != "" and type != "Event" do
url = object.data["url"] || object.data["id"]
"<p><a href=\"#{url}\">#{name}</a></p>#{object.data["content"]}"

View file

@ -0,0 +1 @@
{"type":"FeatureCollection","geocoding":{"version":"0.1.0","attribution":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","licence":"ODbL","query":"N3726208425,R3726208425,W3726208425"},"features":[{"type":"Feature","properties":{"geocoding":{"place_id":45392146,"osm_type":"node","osm_id":3726208425,"osm_key":"place","osm_value":"village","type":"city","label":"Benis, بخش مرکزی, Shabestar County, East Azerbaijan Province, Iran","name":"Benis","country":"Iran","state":"East Azerbaijan Province","county":"Shabestar County","city":"بخش مرکزی","admin":{"level4":"East Azerbaijan Province","level5":"Shabestar County","level6":"بخش مرکزی"}}},"geometry":{"type":"Point","coordinates":[45.7285348,38.212263]}}]}

View file

@ -147,8 +147,10 @@ test "creates notification for event join request" do
CommonAPI.join(other_user, activity.id)
user_notifications = Notification.for_user(user)
[notification] = user_notifications = Notification.for_user(user)
assert length(user_notifications) == 1
assert notification.type == "pleroma:participation_request"
end
test "creates notification for event join approval" do
@ -167,8 +169,10 @@ test "creates notification for event join approval" do
CommonAPI.accept_join_request(user, other_user, activity.data["object"])
user_notifications = Notification.for_user(other_user)
[notification] = user_notifications = Notification.for_user(other_user)
assert length(user_notifications) == 1
assert notification.type == "pleroma:participation_accepted"
end
test "doesn't create notification for events without participation approval" do
@ -217,6 +221,65 @@ test "it sends edited notifications to those who repeated a status" do
end
end
test "creates notifications for edited events for participants" do
user = insert(:user)
other_user = insert(:user)
{:ok, activity} =
CommonAPI.event(user, %{
name: "test event",
status: "test evnet",
join_mode: "free",
start_time: DateTime.from_iso8601("2023-01-01T01:00:00.000Z") |> elem(1)
})
CommonAPI.join(other_user, activity.id)
{:ok, _edit_activity} =
CommonAPI.update_event(user, activity, %{
name: "test event",
status: "test event",
join_mode: "free",
start_time: DateTime.from_iso8601("2023-01-01T01:00:00.000Z") |> elem(1)
})
Pleroma.Tests.ObanHelpers.perform_all()
[notification] = user_notifications = Notification.for_user(other_user)
assert length(user_notifications) == 1
assert notification.type == "pleroma:event_update"
end
test "doesn't create multiple edit notifications for events" do
user = insert(:user)
other_user = insert(:user)
{:ok, activity} =
CommonAPI.event(user, %{
name: "test event",
status: "test evnet",
join_mode: "free",
start_time: DateTime.from_iso8601("2023-01-01T01:00:00.000Z") |> elem(1)
})
CommonAPI.join(other_user, activity.id)
CommonAPI.repeat(activity.id, other_user)
{:ok, _edit_activity} =
CommonAPI.update_event(user, activity, %{
name: "test event",
status: "test event",
join_mode: "free",
start_time: DateTime.from_iso8601("2023-01-01T01:00:00.000Z") |> elem(1)
})
Pleroma.Tests.ObanHelpers.perform_all()
user_notifications = Notification.for_user(other_user)
assert length(user_notifications) == 1
end
test "create_poll_notifications/1" do
[user1, user2, user3, _, _] = insert_list(5, :user)
question = insert(:question, user: user1)

View file

@ -813,6 +813,25 @@ test "with a source object" do
assert status.text == "object source"
end
test "it shows an event" do
event = insert(:event)
activity = insert(:event_activity, event: event)
status = StatusView.render("show.json", activity: activity)
assert status.pleroma.event == %{
name: event.data["name"],
start_time: event.data["startTime"],
end_time: event.data["endTime"],
join_mode: event.data["joinMode"],
participants_count: nil,
location: nil,
join_state: nil,
participation_request_count: nil
}
end
describe "source.json" do
test "with a source object, renders both source and content type" do
note =

View file

@ -55,6 +55,37 @@ test "can't create event that ends before its start", %{conn: conn} do
"error" => "Event can't end before its start"
}
end
test "assigns location from location id", %{conn: conn} do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
conn =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/pleroma/events", %{
"name" => "Event name",
"start_time" => "2023-01-01T01:00:00.000Z",
"end_time" => "2023-01-01T04:00:00.000Z",
"join_mode" => "free",
"location_id" => "3726208425"
})
assert %{
"pleroma" => %{
"event" => %{
"location" => %{
"name" => "Benis",
"longitude" => 45.7285348,
"latitude" => 38.212263,
"street" => " ",
"locality" => "بخش مرکزی",
"region" => "East Azerbaijan Province",
"country" => "Iran"
}
}
}
} = json_response_and_validate_schema(conn, 200)
end
end
test "GET /api/v1/pleroma/events/:id/participations" do
@ -276,7 +307,7 @@ test "accepts a participation request", %{user: user, conn: conn} do
Utils.get_existing_join(other_user.ap_id, activity.data["object"])
end
test "it refuses to accept a request when event is not by the user", %{user: user, conn: conn} do
test "it refuses to accept a request when event is not by the user", %{conn: conn} do
[second_user, third_user] = insert_pair(:user)
{:ok, activity} =

View file

@ -1496,6 +1496,20 @@ def get(
}}
end
def get(
"https://nominatim.openstreetmap.org/lookup?format=geocodejson&osm_ids=N3726208425,R3726208425,W3726208425&accept-language=en&addressdetails=1&namedetails=1",
_,
_,
_
) do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/nominatim_single_result.json"),
headers: [{"content-type", "application/json"}]
}}
end
def get(url, query, body, headers) do
{:error,
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}