1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.RegistrationTest do
6 use Pleroma.DataCase, async: true
10 alias Pleroma.Registration
13 describe "generic changeset" do
14 test "requires :provider, :uid" do
15 registration = build(:registration, provider: nil, uid: nil)
17 cs = Registration.changeset(registration, %{})
21 provider: {"can't be blank", [validation: :required]},
22 uid: {"can't be blank", [validation: :required]}
26 test "ensures uniqueness of [:provider, :uid]" do
27 registration = insert(:registration)
28 registration2 = build(:registration, provider: registration.provider, uid: registration.uid)
30 cs = Registration.changeset(registration2, %{})
37 {"has already been taken",
38 [constraint: :unique, constraint_name: "registrations_provider_uid_index"]}
42 # Note: multiple :uid values per [:user_id, :provider] are intentionally allowed
43 cs2 = Registration.changeset(registration2, %{uid: "available.uid"})
45 assert {:ok, _} = Repo.insert(cs2)
47 cs3 = Registration.changeset(registration2, %{provider: "provider2"})
49 assert {:ok, _} = Repo.insert(cs3)
52 test "allows `nil` :user_id (user-unbound registration)" do
53 registration = build(:registration, user_id: nil)
54 cs = Registration.changeset(registration, %{})
56 assert {:ok, _} = Repo.insert(cs)