From ecfa7e236b36ce10354295a9a848c2e22a52643f Mon Sep 17 00:00:00 2001 From: Inhji Date: Mon, 17 Jul 2023 22:24:17 +0200 Subject: [PATCH] add micropub and note test --- test/chiya/notes_test.exs | 8 ++++++- test/chiya_web/indie/micropub_test.exs | 29 ++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/test/chiya/notes_test.exs b/test/chiya/notes_test.exs index 6e9bd0b..e261b31 100644 --- a/test/chiya/notes_test.exs +++ b/test/chiya/notes_test.exs @@ -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 diff --git a/test/chiya_web/indie/micropub_test.exs b/test/chiya_web/indie/micropub_test.exs index 1d41a64..bba5199 100644 --- a/test/chiya_web/indie/micropub_test.exs +++ b/test/chiya_web/indie/micropub_test.exs @@ -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