From: Roman Chvanikov Date: Fri, 7 Aug 2020 09:18:55 +0000 (+0300) Subject: Update test for RenameInstanceChat migration X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=d7dfa6d27cf140b9d0faed32c3a7a659a0f2e20e;p=akkoma Update test for RenameInstanceChat migration --- diff --git a/test/migrations/20200806175913_rename_instance_chat_test.exs b/test/migrations/20200806175913_rename_instance_chat_test.exs index 66341bd84..acd45600c 100644 --- a/test/migrations/20200806175913_rename_instance_chat_test.exs +++ b/test/migrations/20200806175913_rename_instance_chat_test.exs @@ -8,14 +8,45 @@ defmodule Pleroma.Repo.Migrations.RenameInstanceChatTest do setup do: clear_config([:chat]) setup_all do: require_migration("20200806175913_rename_instance_chat") - test "up/0 migrates chat settings to shout", %{migration: migration} do - insert(:config, group: :pleroma, key: :instance, value: ["chat_limit: 6000"]) - insert(:config, group: :pleroma, key: :chat, value: ["enabled: true"]) + describe "up/0" do + test "migrates chat settings to shout", %{migration: migration} do + insert(:config, group: :pleroma, key: :instance, value: [chat_limit: 6000]) + insert(:config, group: :pleroma, key: :chat, value: [enabled: true]) - migration.up() + assert migration.up() == :ok - assert nil == ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) + assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil + assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil - assert %{value: [limit: 6000, enabled: true]} == ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) + assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}).value == [ + limit: 6000, + enabled: true + ] + end + + test "does nothing when chat settings are not set", %{migration: migration} do + assert migration.up() == :noop + assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil + assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil + end + end + + describe "down/0" do + test "migrates shout settings back to instance and chat", %{migration: migration} do + insert(:config, group: :pleroma, key: :shout, value: [limit: 42, enabled: true]) + + assert migration.down() == :ok + + assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}).value == [enabled: true] + assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}).value == [chat_limit: 42] + assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil + end + + test "does nothing when shout settings are not set", %{migration: migration} do + assert migration.down() == :noop + assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil + assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil + assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil + end end end