Merge pull request 'Make UserNote comment default to the empty string.' (#530) from provable_ascent/akkoma:provable_ascent-patch-1 into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/530
This commit is contained in:
commit
f72d773cc3
2 changed files with 40 additions and 1 deletions
|
@ -31,7 +31,7 @@ defmodule Pleroma.UserNote do
|
||||||
UserNote
|
UserNote
|
||||||
|> where(source_id: ^source.id, target_id: ^target.id)
|
|> where(source_id: ^source.id, target_id: ^target.id)
|
||||||
|> Repo.one() do
|
|> Repo.one() do
|
||||||
note.comment
|
note.comment || ""
|
||||||
else
|
else
|
||||||
_ -> ""
|
_ -> ""
|
||||||
end
|
end
|
||||||
|
|
39
test/pleroma/user_note_test.exs
Normal file
39
test/pleroma/user_note_test.exs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.UserNoteTest do
|
||||||
|
alias Pleroma.UserNote
|
||||||
|
|
||||||
|
use Pleroma.DataCase, async: false
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
describe "show/2" do
|
||||||
|
setup do
|
||||||
|
{:ok, users: insert_list(2, :user)}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "if record does not exist, returns empty string", %{users: [user1, user2]} do
|
||||||
|
comment = UserNote.show(user1, user2)
|
||||||
|
|
||||||
|
assert comment == ""
|
||||||
|
end
|
||||||
|
|
||||||
|
test "if record exists with comment == nil, returns empty string", %{users: [user1, user2]} do
|
||||||
|
UserNote.create(user1, user2, nil)
|
||||||
|
|
||||||
|
comment = UserNote.show(user1, user2)
|
||||||
|
|
||||||
|
assert comment == ""
|
||||||
|
end
|
||||||
|
|
||||||
|
test "if record exists with non-nil comment, returns comment", %{users: [user1, user2]} do
|
||||||
|
expected_comment = "hello"
|
||||||
|
UserNote.create(user1, user2, expected_comment)
|
||||||
|
|
||||||
|
comment = UserNote.show(user1, user2)
|
||||||
|
|
||||||
|
assert comment == expected_comment
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue