1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
6 use Pleroma.Web.ConnCase
10 import ExUnit.CaptureLog
11 import Pleroma.Factory
14 setup do: oauth_access(["read"])
16 setup %{user: user} do
17 other_user = insert(:user)
18 host = Config.get([Pleroma.Web.Endpoint, :url, :host])
19 url500 = "http://test500?#{host}&#{user.nickname}"
20 url200 = "http://test200?#{host}&#{user.nickname}"
23 %{method: :get, url: ^url500} ->
24 %Tesla.Env{status: 500, body: "bad request"}
26 %{method: :get, url: ^url200} ->
30 ~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
32 }","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
36 [other_user: other_user]
39 clear_config(:suggestions)
41 test "returns empty result when suggestions disabled", %{conn: conn} do
42 Config.put([:suggestions, :enabled], false)
46 |> get("/api/v1/suggestions")
52 test "returns error", %{conn: conn} do
53 Config.put([:suggestions, :enabled], true)
54 Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
56 assert capture_log(fn ->
59 |> get("/api/v1/suggestions")
62 assert res == "Something went wrong"
63 end) =~ "Could not retrieve suggestions"
66 test "returns suggestions", %{conn: conn, other_user: other_user} do
67 Config.put([:suggestions, :enabled], true)
68 Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
72 |> get("/api/v1/suggestions")
78 "avatar" => "https://social.heldscal.la/avatar/201.jpeg",
79 "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
83 "acct" => other_user.ap_id,
84 "avatar" => "https://social.heldscal.la/avatar/202.jpeg",
85 "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",