Update
This commit is contained in:
parent
8f63a831c4
commit
f963620cf0
11 changed files with 135 additions and 20 deletions
75
test/nulla_web/controllers/note_controller_test.exs
Normal file
75
test/nulla_web/controllers/note_controller_test.exs
Normal file
|
@ -0,0 +1,75 @@
|
|||
defmodule NullaWeb.NoteControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
alias Nulla.KeyGen
|
||||
alias Nulla.Snowflake
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Note
|
||||
|
||||
describe "GET /notes/id" do
|
||||
test "returns ActivityPub JSON with note", %{conn: conn} 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")
|
||||
})
|
||||
|
||||
note_id = Snowflake.next_id()
|
||||
|
||||
{:ok, note} =
|
||||
Note.create_note(%{
|
||||
id: note_id,
|
||||
url: "#{actor.url}/#{note_id}",
|
||||
content: "Hello World from Nulla!",
|
||||
language: "en",
|
||||
actor_id: actor.id
|
||||
})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(~p"/users/#{actor.preferredUsername}/notes/#{note.id}")
|
||||
|
||||
assert response = json_response(conn, 200)
|
||||
|
||||
assert is_list(response["@context"])
|
||||
assert response["id"] == "http://localhost/users/test/notes/#{note.id}"
|
||||
assert response["type"] == "Note"
|
||||
assert response["summary"] == nil
|
||||
assert response["inReplyTo"] == nil
|
||||
assert {:ok, _dt, _offset} = DateTime.from_iso8601(response["published"])
|
||||
assert response["url"] == note.url
|
||||
assert response["attributedTo"] == "http://localhost/users/test"
|
||||
assert is_list(response["to"])
|
||||
assert is_list(response["cc"])
|
||||
assert response["sensitive"] == false
|
||||
assert is_binary(response["content"])
|
||||
assert is_map(response["contentMap"])
|
||||
assert is_list(response["attachment"])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue