logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

flake_id_test.exs (1455B)


      1 # Pleroma: A lightweight social networking server
      2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
      3 # SPDX-License-Identifier: AGPL-3.0-only
      4 
      5 defmodule Pleroma.FlakeIdTest do
      6   use Pleroma.DataCase
      7   import Kernel, except: [to_string: 1]
      8   import Pleroma.FlakeId
      9 
     10   describe "fake flakes (compatibility with older serial integers)" do
     11     test "from_string/1" do
     12       fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
     13       assert from_string("42") == fake_flake
     14       assert from_string(42) == fake_flake
     15     end
     16 
     17     test "zero or -1 is a null flake" do
     18       fake_flake = <<0::integer-size(128)>>
     19       assert from_string("0") == fake_flake
     20       assert from_string("-1") == fake_flake
     21     end
     22 
     23     test "to_string/1" do
     24       fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
     25       assert to_string(fake_flake) == "42"
     26     end
     27   end
     28 
     29   test "ecto type behaviour" do
     30     flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>>
     31     flake_s = "9eoozpwTul5mjSEDRI"
     32 
     33     assert cast(flake) == {:ok, flake_s}
     34     assert cast(flake_s) == {:ok, flake_s}
     35 
     36     assert load(flake) == {:ok, flake_s}
     37     assert load(flake_s) == {:ok, flake_s}
     38 
     39     assert dump(flake_s) == {:ok, flake}
     40     assert dump(flake) == {:ok, flake}
     41   end
     42 
     43   test "is_flake_id?/1" do
     44     assert is_flake_id?("9eoozpwTul5mjSEDRI")
     45     refute is_flake_id?("http://example.com/activities/3ebbadd1-eb14-4e20-8118-b6f79c0c7b0b")
     46   end
     47 end