devel #215
2 changed files with 34 additions and 3 deletions
|
@ -2,9 +2,11 @@ defmodule Chiya.NotesTest do
|
|||
use Chiya.DataCase
|
||||
|
||||
import Chiya.NotesFixtures
|
||||
import Chiya.ChannelsFixtures
|
||||
|
||||
alias Chiya.Notes
|
||||
alias Chiya.Notes.Note
|
||||
alias Chiya.Channels.Channel
|
||||
|
||||
describe "notes" do
|
||||
@invalid_attrs %{content: nil, kind: nil, name: nil, published_at: nil, slug: nil, url: nil}
|
||||
|
@ -20,12 +22,15 @@ defmodule Chiya.NotesTest do
|
|||
end
|
||||
|
||||
test "create_note/1 with valid data creates a note" do
|
||||
channel = channel_fixture()
|
||||
|
||||
valid_attrs = %{
|
||||
content: "some content",
|
||||
kind: "post",
|
||||
name: "some name",
|
||||
published_at: ~N[2023-03-04 16:22:00],
|
||||
url: "some url"
|
||||
url: "some url",
|
||||
channels: [channel]
|
||||
}
|
||||
|
||||
assert {:ok, %Note{} = note} = Notes.create_note(valid_attrs)
|
||||
|
@ -35,6 +40,7 @@ defmodule Chiya.NotesTest do
|
|||
assert note.published_at == ~N[2023-03-04 16:22:00]
|
||||
assert note.slug == "some-name"
|
||||
assert note.url == "some url"
|
||||
assert [%Channel{}] = note.channels
|
||||
end
|
||||
|
||||
test "create_note/1 with invalid data returns error changeset" do
|
||||
|
|
|
@ -2,6 +2,8 @@ defmodule ChiyaWeb.MicropubTest do
|
|||
use Chiya.DataCase
|
||||
|
||||
alias ChiyaWeb.Indie.Micropub
|
||||
alias Chiya.Notes.Note
|
||||
alias Chiya.Channels.Channel
|
||||
|
||||
@valid_props %{
|
||||
"content" => ["this is a test"]
|
||||
|
@ -10,9 +12,32 @@ defmodule ChiyaWeb.MicropubTest do
|
|||
describe "create_note/3" do
|
||||
test "creates a note with valid attributes" do
|
||||
assert {:ok, :created, url} =
|
||||
Micropub.create_note("entry", @valid_props, nil)
|
||||
Micropub.create_note("entry", @valid_props)
|
||||
|
||||
assert url =~ "this-is-a-test"
|
||||
note = Chiya.Notes.get_note_by_slug_preloaded("this-is-a-test")
|
||||
|
||||
assert url =~ note.slug
|
||||
assert %Note{} = note
|
||||
assert [%Channel{}] = note.channels
|
||||
end
|
||||
end
|
||||
|
||||
setup do
|
||||
{:ok, channel} =
|
||||
Chiya.Channels.create_channel(%{
|
||||
name: "Home",
|
||||
content: "Home channel"
|
||||
})
|
||||
|
||||
settings = Chiya.Site.get_settings()
|
||||
|
||||
Chiya.Site.update_setting(settings, %{
|
||||
home_channel_id: channel.id,
|
||||
default_channel_id: channel.id,
|
||||
micropub_channel_id: channel.id,
|
||||
wiki_channel_id: channel.id
|
||||
})
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue