summaryrefslogtreecommitdiff
path: root/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
blob: 2ffc1b145ac4aa65c6d29b1f05300f2458909741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do
  use Pleroma.DataCase
  import Pleroma.Factory
  import Pleroma.Tests.Helpers
  alias Pleroma.ConfigDB

  setup do: clear_config(Pleroma.Upload)
  setup do: clear_config(Pleroma.Uploaders.S3)
  setup_all do: require_migration("20210113225652_deprecate_public_endpoint")

  test "up/0 migrates public_endpoint to base_url", %{migration: migration} do
    s3_values = [
      public_endpoint: "https://coolhost.com/",
      bucket: "secret_bucket"
    ]

    insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)

    upload_values = [
      uploader: Pleroma.Uploaders.S3
    ]

    insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)

    migration.up()

    assert [bucket: "secret_bucket"] ==
             ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value

    assert [uploader: Pleroma.Uploaders.S3, base_url: "https://coolhost.com/"] ==
             ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
  end

  test "down/0 reverts base_url to public_endpoint", %{migration: migration} do
    s3_values = [
      bucket: "secret_bucket"
    ]

    insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)

    upload_values = [
      uploader: Pleroma.Uploaders.S3,
      base_url: "https://coolhost.com/"
    ]

    insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)

    migration.down()

    assert [bucket: "secret_bucket", public_endpoint: "https://coolhost.com/"] ==
             ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value

    assert [uploader: Pleroma.Uploaders.S3] ==
             ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
  end
end