b8d073e11c325df240e17b8205c01b1627772ccb
[akkoma] / test / application_requirements_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ApplicationRequirementsTest do
6 use Pleroma.DataCase
7 import ExUnit.CaptureLog
8 import Mock
9
10 describe "check_rum!" do
11 setup_with_mocks([
12 {Pleroma.ApplicationRequirements, [:passthrough],
13 [check_migrations_applied!: fn _ -> :ok end]}
14 ]) do
15 :ok
16 end
17
18 setup do: clear_config([:database, :rum_enabled])
19
20 test "raises if rum is enabled and detects unapplied rum migrations" do
21 Pleroma.Config.put([:database, :rum_enabled], true)
22
23 assert_raise Pleroma.ApplicationRequirements.VerifyError,
24 "Unapplied RUM Migrations detected",
25 fn ->
26 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
27 end
28 end
29
30 test "raises if rum is disabled and detects rum migrations" do
31 Pleroma.Config.put([:database, :rum_enabled], false)
32
33 with_mocks([
34 {
35 Pleroma.Repo,
36 [:passthrough],
37 [exists?: fn _, _ -> true end]
38 }
39 ]) do
40 assert_raise Pleroma.ApplicationRequirements.VerifyError,
41 "RUM Migrations detected",
42 fn ->
43 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
44 end
45 end
46 end
47
48 test "doesn't do anything if rum enabled and applied migrations" do
49 Pleroma.Config.put([:database, :rum_enabled], true)
50
51 with_mocks([
52 {
53 Pleroma.Repo,
54 [:passthrough],
55 [exists?: fn _, _ -> true end]
56 }
57 ]) do
58 assert Pleroma.ApplicationRequirements.verify!() == :ok
59 end
60 end
61
62 test "doesn't do anything if rum disabled" do
63 Pleroma.Config.put([:database, :rum_enabled], false)
64 assert Pleroma.ApplicationRequirements.verify!() == :ok
65 end
66 end
67
68 describe "check_migrations_applied!" do
69 setup_with_mocks([
70 {Ecto.Migrator, [],
71 [
72 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
73 migrations: fn Pleroma.Repo ->
74 [
75 {:up, 20_191_128_153_944, "fix_missing_following_count"},
76 {:up, 20_191_203_043_610, "create_report_notes"},
77 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
78 ]
79 end
80 ]}
81 ]) do
82 :ok
83 end
84
85 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
86
87 test "raises if it detects unapplied migrations" do
88 assert_raise Pleroma.ApplicationRequirements.VerifyError,
89 "Unapplied Migrations detected",
90 fn ->
91 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
92 end
93 end
94
95 test "doesn't do anything if disabled" do
96 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
97
98 assert :ok == Pleroma.ApplicationRequirements.verify!()
99 end
100 end
101 end