Skip to content

Commit 08d24b7

Browse files
committed
added multiple tests for Note.Id.to_binary/1
1 parent 1b8c535 commit 08d24b7

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/nostr/models/note/id_test.exs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
defmodule Nostr.Models.Note.IdTest do
22
use ExUnit.Case
33

4-
doctest Nostr.Models.Note.Id
4+
alias Nostr.Models.Note
5+
6+
doctest Note.Id
7+
8+
test "convert an bech32 note id with to_binary/1" do
9+
bech32_note_id = "note1qkjgra6cm5ms6m88kqdapfjnxm8q50lcurevtpvm4f6pfs8j5sxq90f098"
10+
11+
{:ok, note_id} = Note.Id.to_binary(bech32_note_id)
12+
13+
assert <<0x05A481F758DD370D6CE7B01BD0A65336CE0A3FF8E0F2C5859BAA7414C0F2A40C::256>> == note_id
14+
end
15+
16+
test "convert a binary note id to binary with to_binary/1" do
17+
note_id = <<0x05A481F758DD370D6CE7B01BD0A65336CE0A3FF8E0F2C5859BAA7414C0F2A40C::256>>
18+
19+
{:ok, binary_note_id} = Note.Id.to_binary(note_id)
20+
21+
assert note_id == binary_note_id
22+
end
23+
24+
test "try converting an invalid string to binary note id with to_binary/1" do
25+
invalid_note_id = "this_won't_work"
26+
27+
{:error, message} = Note.Id.to_binary(invalid_note_id)
28+
29+
assert message =~ "is not a valid note id"
30+
end
531
end

0 commit comments

Comments
 (0)