Update tests
This commit is contained in:
parent
406cd1798c
commit
c30541830f
10 changed files with 134 additions and 284 deletions
|
@ -1,53 +1,17 @@
|
|||
defmodule NullaWeb.NoteControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
alias Nulla.KeyGen
|
||||
alias Nulla.Snowflake
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Note
|
||||
|
||||
setup do
|
||||
Nulla.Fixtures.Data.create()
|
||||
:ok
|
||||
end
|
||||
|
||||
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
|
||||
})
|
||||
actor = Actor.get_actor(preferredUsername: "test")
|
||||
note = Note.get_note(actor_id: actor.id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
@ -73,55 +37,16 @@ defmodule NullaWeb.NoteControllerTest do
|
|||
end
|
||||
|
||||
test "renders HTML if Accept header is regular", %{conn: conn} do
|
||||
{publicKeyPem, _privateKeyPem} = KeyGen.gen()
|
||||
actor = Actor.get_actor(preferredUsername: "test")
|
||||
note = Note.get_note(actor_id: actor.id)
|
||||
|
||||
{: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 = get(conn, ~p"/users/test/notes/#{note.id}")
|
||||
conn = get(conn, ~p"/@test/#{note.id}")
|
||||
|
||||
assert html_response(conn, 200) =~ note.content
|
||||
end
|
||||
|
||||
test "returns 404 if note not found", %{conn: conn} do
|
||||
conn = get(conn, ~p"/users/test/notes/nonexistent")
|
||||
conn = get(conn, ~p"/@test/nonexistent")
|
||||
|
||||
assert json_response(conn, 404)["error"] == "Not Found"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue