Validators: ObjectID is an http uri.
[akkoma] / test / web / activity_pub / object_validators / types / object_id_test.exs
1 defmodule Pleroma.Web.ObjectValidators.Types.ObjectIDTest do
2 alias Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID
3 use Pleroma.DataCase
4
5 @uris [
6 "http://lain.com/users/lain",
7 "http://lain.com",
8 "https://lain.com/object/1"
9 ]
10
11 @non_uris [
12 "https://",
13 "rin"
14 ]
15
16 test "it rejects integers" do
17 assert :error == ObjectID.cast(1)
18 end
19
20 test "it accepts http uris" do
21 Enum.each(@uris, fn uri ->
22 assert {:ok, uri} == ObjectID.cast(uri)
23 end)
24 end
25
26 test "it accepts an object with a nested uri id" do
27 Enum.each(@uris, fn uri ->
28 assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
29 end)
30 end
31
32 test "it rejects non-uri strings" do
33 Enum.each(@non_uris, fn non_uri ->
34 assert :error == ObjectID.cast(non_uri)
35 assert :error == ObjectID.cast(%{"id" => non_uri})
36 end)
37 end
38 end