nulla/test/support/fixtures/data.ex

99 lines
3.1 KiB
Elixir

defmodule Nulla.Fixtures.Data do
alias Nulla.KeyGen
alias Nulla.Models.User
alias Nulla.Models.Actor
alias Nulla.Models.Note
def create do
endpoint_config = Application.fetch_env!(:nulla, NullaWeb.Endpoint)
ip = endpoint_config[:http][:ip]
host = :inet_parse.ntoa(ip) |> to_string()
port = endpoint_config[:http][:port]
base_url = "http://#{host}:#{port}"
{publicKeyPem, privateKeyPem} = KeyGen.gen()
{:ok, actor} =
Actor.create_actor(%{
domain: "localhost",
ap_id: "#{base_url}/users/test",
type: "Person",
following: "#{base_url}/users/test/following",
followers: "#{base_url}/users/test/followers",
inbox: "#{base_url}/users/test/inbox",
outbox: "#{base_url}/users/test/outbox",
featured: "#{base_url}/users/test/collections/featured",
featuredTags: "#{base_url}/users/test/collections/tags",
preferredUsername: "test",
name: "Test",
summary: "Test User",
url: "#{base_url}/@test",
manuallyApprovesFollowers: false,
discoverable: true,
indexable: true,
published: DateTime.utc_now(),
memorial: false,
publicKey:
Jason.OrderedObject.new(
id: "#{base_url}/users/test#main-key",
owner: "#{base_url}/users/test",
publicKeyPem: publicKeyPem
),
endpoints: Jason.OrderedObject.new(sharedInbox: "#{base_url}/inbox")
})
User.create_user(%{
id: actor.id,
email: "test@localhost",
password: "password",
privateKeyPem: privateKeyPem,
last_active_at: DateTime.utc_now()
})
Note.create_note(%{
actor_url: actor.url,
content: "Hello World from Nulla!",
language: "en",
actor_id: actor.id
})
{publicKeyPem, privateKeyPem} = KeyGen.gen()
{:ok, actor} =
Actor.create_actor(%{
domain: "localhost",
ap_id: "#{base_url}/users/test2",
type: "Person",
following: "#{base_url}/users/test2/following",
followers: "#{base_url}/users/test2/followers",
inbox: "#{base_url}/users/test2/inbox",
outbox: "#{base_url}/users/test2/outbox",
featured: "#{base_url}/users/test2/collections/featured",
featuredTags: "#{base_url}/users/test2/collections/tags",
preferredUsername: "test2",
name: "Test",
summary: "Test User",
url: "#{base_url}/@test2",
manuallyApprovesFollowers: false,
discoverable: true,
indexable: true,
published: DateTime.utc_now(),
memorial: false,
publicKey:
Jason.OrderedObject.new(
id: "#{base_url}/users/test2#main-key",
owner: "#{base_url}/users/test2",
publicKeyPem: publicKeyPem
),
endpoints: Jason.OrderedObject.new(sharedInbox: "#{base_url}/inbox")
})
User.create_user(%{
id: actor.id,
email: "test2@localhost",
password: "password",
privateKeyPem: privateKeyPem,
last_active_at: DateTime.utc_now()
})
end
end