Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
[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 alias Pleroma.Repo
11
12 describe "check_rum!" do
13 setup_with_mocks([
14 {Pleroma.ApplicationRequirements, [:passthrough],
15 [check_migrations_applied!: fn _ -> :ok end]}
16 ]) do
17 :ok
18 end
19
20 setup do: clear_config([:database, :rum_enabled])
21
22 test "raises if rum is enabled and detects unapplied rum migrations" do
23 Pleroma.Config.put([:database, :rum_enabled], true)
24
25 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
26 assert_raise Pleroma.ApplicationRequirements.VerifyError,
27 "Unapplied RUM Migrations detected",
28 fn ->
29 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
30 end
31 end
32 end
33
34 test "raises if rum is disabled and detects rum migrations" do
35 Pleroma.Config.put([:database, :rum_enabled], false)
36
37 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
38 assert_raise Pleroma.ApplicationRequirements.VerifyError,
39 "RUM Migrations detected",
40 fn ->
41 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
42 end
43 end
44 end
45
46 test "doesn't do anything if rum enabled and applied migrations" do
47 Pleroma.Config.put([:database, :rum_enabled], true)
48
49 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
50 assert Pleroma.ApplicationRequirements.verify!() == :ok
51 end
52 end
53
54 test "doesn't do anything if rum disabled" do
55 Pleroma.Config.put([:database, :rum_enabled], false)
56
57 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
58 assert Pleroma.ApplicationRequirements.verify!() == :ok
59 end
60 end
61 end
62
63 describe "check_migrations_applied!" do
64 setup_with_mocks([
65 {Ecto.Migrator, [],
66 [
67 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
68 migrations: fn Repo ->
69 [
70 {:up, 20_191_128_153_944, "fix_missing_following_count"},
71 {:up, 20_191_203_043_610, "create_report_notes"},
72 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
73 ]
74 end
75 ]}
76 ]) do
77 :ok
78 end
79
80 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
81
82 test "raises if it detects unapplied migrations" do
83 assert_raise Pleroma.ApplicationRequirements.VerifyError,
84 "Unapplied Migrations detected",
85 fn ->
86 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
87 end
88 end
89
90 test "doesn't do anything if disabled" do
91 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
92
93 assert :ok == Pleroma.ApplicationRequirements.verify!()
94 end
95 end
96 end