logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

20200724133313_move_welcome_settings_test.exs (4293B)


  1. defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
  2. use Pleroma.DataCase
  3. import Pleroma.Factory
  4. import Pleroma.Tests.Helpers
  5. alias Pleroma.ConfigDB
  6. setup_all do: require_migration("20200724133313_move_welcome_settings")
  7. describe "up/0" do
  8. test "converts welcome settings", %{migration: migration} do
  9. insert(:config,
  10. group: :pleroma,
  11. key: :instance,
  12. value: [
  13. welcome_message: "Test message",
  14. welcome_user_nickname: "jimm",
  15. name: "Pleroma"
  16. ]
  17. )
  18. migration.up()
  19. instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  20. welcome_config = ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
  21. assert instance_config.value == [name: "Pleroma"]
  22. assert welcome_config.value == [
  23. direct_message: %{
  24. enabled: true,
  25. message: "Test message",
  26. sender_nickname: "jimm"
  27. },
  28. email: %{
  29. enabled: false,
  30. html: "Welcome to <%= instance_name %>",
  31. sender: nil,
  32. subject: "Welcome to <%= instance_name %>",
  33. text: "Welcome to <%= instance_name %>"
  34. }
  35. ]
  36. end
  37. test "does nothing when message empty", %{migration: migration} do
  38. insert(:config,
  39. group: :pleroma,
  40. key: :instance,
  41. value: [
  42. welcome_message: "",
  43. welcome_user_nickname: "jimm",
  44. name: "Pleroma"
  45. ]
  46. )
  47. migration.up()
  48. instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  49. refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
  50. assert instance_config.value == [name: "Pleroma"]
  51. end
  52. test "does nothing when welcome_message not set", %{migration: migration} do
  53. insert(:config,
  54. group: :pleroma,
  55. key: :instance,
  56. value: [welcome_user_nickname: "jimm", name: "Pleroma"]
  57. )
  58. migration.up()
  59. instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  60. refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
  61. assert instance_config.value == [name: "Pleroma"]
  62. end
  63. end
  64. describe "down/0" do
  65. test "revert new settings to old when instance setting not exists", %{migration: migration} do
  66. insert(:config,
  67. group: :pleroma,
  68. key: :welcome,
  69. value: [
  70. direct_message: %{
  71. enabled: true,
  72. message: "Test message",
  73. sender_nickname: "jimm"
  74. },
  75. email: %{
  76. enabled: false,
  77. html: "Welcome to <%= instance_name %>",
  78. sender: nil,
  79. subject: "Welcome to <%= instance_name %>",
  80. text: "Welcome to <%= instance_name %>"
  81. }
  82. ]
  83. )
  84. migration.down()
  85. refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
  86. instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  87. assert instance_config.value == [
  88. welcome_user_nickname: "jimm",
  89. welcome_message: "Test message"
  90. ]
  91. end
  92. test "revert new settings to old when instance setting exists", %{migration: migration} do
  93. insert(:config, group: :pleroma, key: :instance, value: [name: "Pleroma App"])
  94. insert(:config,
  95. group: :pleroma,
  96. key: :welcome,
  97. value: [
  98. direct_message: %{
  99. enabled: true,
  100. message: "Test message",
  101. sender_nickname: "jimm"
  102. },
  103. email: %{
  104. enabled: false,
  105. html: "Welcome to <%= instance_name %>",
  106. sender: nil,
  107. subject: "Welcome to <%= instance_name %>",
  108. text: "Welcome to <%= instance_name %>"
  109. }
  110. ]
  111. )
  112. migration.down()
  113. refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
  114. instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  115. assert instance_config.value == [
  116. name: "Pleroma App",
  117. welcome_user_nickname: "jimm",
  118. welcome_message: "Test message"
  119. ]
  120. end
  121. end
  122. end