First
[anni] / test / pleroma / repo / migrations / deprecate_public_endpoint_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do
6   use Pleroma.DataCase
7   import Pleroma.Factory
8   import Pleroma.Tests.Helpers
9   alias Pleroma.ConfigDB
10
11   setup do: clear_config(Pleroma.Upload)
12   setup do: clear_config(Pleroma.Uploaders.S3)
13   setup_all do: require_migration("20210113225652_deprecate_public_endpoint")
14
15   test "up/0 migrates public_endpoint to base_url", %{migration: migration} do
16     s3_values = [
17       public_endpoint: "https://coolhost.com/",
18       bucket: "secret_bucket"
19     ]
20
21     insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
22
23     upload_values = [
24       uploader: Pleroma.Uploaders.S3
25     ]
26
27     insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
28
29     migration.up()
30
31     assert [bucket: "secret_bucket"] ==
32              ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
33
34     assert [uploader: Pleroma.Uploaders.S3, base_url: "https://coolhost.com/"] ==
35              ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
36   end
37
38   test "down/0 reverts base_url to public_endpoint", %{migration: migration} do
39     s3_values = [
40       bucket: "secret_bucket"
41     ]
42
43     insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
44
45     upload_values = [
46       uploader: Pleroma.Uploaders.S3,
47       base_url: "https://coolhost.com/"
48     ]
49
50     insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
51
52     migration.down()
53
54     assert [bucket: "secret_bucket", public_endpoint: "https://coolhost.com/"] ==
55              ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
56
57     assert [uploader: Pleroma.Uploaders.S3] ==
58              ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
59   end
60 end