1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ApplicationRequirementsTest do
7 import ExUnit.CaptureLog
12 describe "check_confirmation_accounts!" do
14 {Pleroma.ApplicationRequirements, [:passthrough],
16 check_migrations_applied!: fn _ -> :ok end
22 setup do: clear_config([:instance, :account_activation_required])
24 test "raises if account confirmation is required but mailer isn't enable" do
25 Pleroma.Config.put([:instance, :account_activation_required], true)
26 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
28 assert_raise Pleroma.ApplicationRequirements.VerifyError,
29 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
31 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
35 test "doesn't do anything if account confirmation is disabled" do
36 Pleroma.Config.put([:instance, :account_activation_required], false)
37 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
38 assert Pleroma.ApplicationRequirements.verify!() == :ok
41 test "doesn't do anything if account confirmation is required and mailer is enabled" do
42 Pleroma.Config.put([:instance, :account_activation_required], true)
43 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
44 assert Pleroma.ApplicationRequirements.verify!() == :ok
48 describe "check_rum!" do
50 {Pleroma.ApplicationRequirements, [:passthrough],
51 [check_migrations_applied!: fn _ -> :ok end]}
56 setup do: clear_config([:database, :rum_enabled])
58 test "raises if rum is enabled and detects unapplied rum migrations" do
59 Pleroma.Config.put([:database, :rum_enabled], true)
61 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
62 assert_raise Pleroma.ApplicationRequirements.VerifyError,
63 "Unapplied RUM Migrations detected",
65 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
70 test "raises if rum is disabled and detects rum migrations" do
71 Pleroma.Config.put([:database, :rum_enabled], false)
73 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
74 assert_raise Pleroma.ApplicationRequirements.VerifyError,
75 "RUM Migrations detected",
77 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
82 test "doesn't do anything if rum enabled and applied migrations" do
83 Pleroma.Config.put([:database, :rum_enabled], true)
85 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
86 assert Pleroma.ApplicationRequirements.verify!() == :ok
90 test "doesn't do anything if rum disabled" do
91 Pleroma.Config.put([:database, :rum_enabled], false)
93 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
94 assert Pleroma.ApplicationRequirements.verify!() == :ok
99 describe "check_migrations_applied!" do
103 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
104 migrations: fn Repo ->
106 {:up, 20_191_128_153_944, "fix_missing_following_count"},
107 {:up, 20_191_203_043_610, "create_report_notes"},
108 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
116 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
118 test "raises if it detects unapplied migrations" do
119 assert_raise Pleroma.ApplicationRequirements.VerifyError,
120 "Unapplied Migrations detected",
122 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
126 test "doesn't do anything if disabled" do
127 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
129 assert :ok == Pleroma.ApplicationRequirements.verify!()