summaryrefslogtreecommitdiff
path: root/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs
blob: 38bca41cfdb0e26802faf49722a015b3a9972bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
  alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
  use Pleroma.DataCase, async: true

  @uris [
    "http://lain.com/users/lain",
    "http://lain.com",
    "https://lain.com/object/1"
  ]

  @non_uris [
    "https://",
    "rin",
    1,
    :x,
    %{"1" => 2}
  ]

  test "it accepts http uris" do
    Enum.each(@uris, fn uri ->
      assert {:ok, uri} == ObjectID.cast(uri)
    end)
  end

  test "it accepts an object with a nested uri id" do
    Enum.each(@uris, fn uri ->
      assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
    end)
  end

  test "it rejects non-uri strings" do
    Enum.each(@non_uris, fn non_uri ->
      assert :error == ObjectID.cast(non_uri)
      assert :error == ObjectID.cast(%{"id" => non_uri})
    end)
  end
end