38bca41cfdb0e26802faf49722a015b3a9972bf6
[anni] / test / pleroma / ecto_type / activity_pub / object_validators / object_id_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
6   alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
7   use Pleroma.DataCase, async: true
8
9   @uris [
10     "http://lain.com/users/lain",
11     "http://lain.com",
12     "https://lain.com/object/1"
13   ]
14
15   @non_uris [
16     "https://",
17     "rin",
18     1,
19     :x,
20     %{"1" => 2}
21   ]
22
23   test "it accepts http uris" do
24     Enum.each(@uris, fn uri ->
25       assert {:ok, uri} == ObjectID.cast(uri)
26     end)
27   end
28
29   test "it accepts an object with a nested uri id" do
30     Enum.each(@uris, fn uri ->
31       assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
32     end)
33   end
34
35   test "it rejects non-uri strings" do
36     Enum.each(@non_uris, fn non_uri ->
37       assert :error == ObjectID.cast(non_uri)
38       assert :error == ObjectID.cast(%{"id" => non_uri})
39     end)
40   end
41 end