defmodule NullaWeb.FollowControllerTest do use NullaWeb.ConnCase alias Nulla.KeyGen alias Nulla.Models.User alias Nulla.Models.Actor setup do {publicKeyPem, privateKeyPem} = KeyGen.gen() {:ok, actor} = Actor.create_actor(%{ domain: "localhost", ap_id: "http://localhost/users/test", type: "Person", following: "http://localhost/users/test/following", followers: "http://localhost/users/test/followers", inbox: "http://localhost/users/test/inbox", outbox: "http://localhost/users/test/outbox", featured: "http://localhost/users/test/collections/featured", featuredTags: "http://localhost/users/test/collections/tags", preferredUsername: "test", name: "Test", summary: "Test User", url: "http://localhost/@test", manuallyApprovesFollowers: false, discoverable: true, indexable: true, published: DateTime.utc_now(), memorial: false, publicKey: Jason.OrderedObject.new( id: "http://localhost/users/test#main-key", owner: "http://localhost/users/test", publicKeyPem: publicKeyPem ), endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox") }) User.create_user(%{ id: actor.id, email: "test@localhost", password: "password", privateKeyPem: privateKeyPem, last_active_at: DateTime.utc_now() }) :ok end describe "GET /users/username/following" do test "returns ActivityPub JSON of following", %{conn: conn} do conn = conn |> get(~p"/users/test/following") assert response = json_response(conn, 200) assert response["id"] == "http://localhost/users/test/following" assert response["type"] == "OrderedCollection" assert response["totalItems"] == 0 assert response["first"] == "http://localhost/users/test/following?page=1" end test "returns ActivityPub JSON of following with page", %{conn: conn} do conn = conn |> get(~p"/users/test/following?page=1") assert response = json_response(conn, 200) assert response["id"] == "http://localhost/users/test/following?page=1" assert response["type"] == "OrderedCollectionPage" assert response["totalItems"] == 0 assert response["partOf"] == "http://localhost/users/test/following" assert is_list(response["orderedItems"]) end test "returns first page with invalid value", %{conn: conn} do conn = conn |> get(~p"/users/test/following?page=abc") assert conn.status == 200 end end describe "GET /users/username/followers" do test "returns ActivityPub JSON of followers", %{conn: conn} do conn = conn |> get(~p"/users/test/followers") assert response = json_response(conn, 200) assert response["id"] == "http://localhost/users/test/followers" assert response["type"] == "OrderedCollection" assert response["totalItems"] == 0 assert response["first"] == "http://localhost/users/test/followers?page=1" end test "returns ActivityPub JSON of followers with page", %{conn: conn} do conn = conn |> get(~p"/users/test/followers?page=1") assert response = json_response(conn, 200) assert response["id"] == "http://localhost/users/test/followers?page=1" assert response["type"] == "OrderedCollectionPage" assert response["totalItems"] == 0 assert response["partOf"] == "http://localhost/users/test/followers" assert is_list(response["orderedItems"]) end test "returns first page with invalid value", %{conn: conn} do conn = conn |> get(~p"/users/test/followers?page=abc") assert conn.status == 200 end end end