From 83479c5aae37289891894b97e987b4dabd19630a Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Mon, 27 Jan 2025 17:36:59 -0500 Subject: [PATCH] test: Add tests for `Config.modify_configuration_code/5` (#210) --- test/igniter/project/config_test.exs | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/igniter/project/config_test.exs b/test/igniter/project/config_test.exs index 0ef5134..2739ce6 100644 --- a/test/igniter/project/config_test.exs +++ b/test/igniter/project/config_test.exs @@ -509,4 +509,42 @@ defmodule Igniter.Project.ConfigTest do false end end + + describe "modify_configuration_code/5" do + test "replace existing config" do + zipper = + ~s""" + import Config + config :fake, foo: [bar: "baz"] + """ + |> Sourceror.parse_string!() + |> Sourceror.Zipper.zip() + + config = + zipper + |> Igniter.Project.Config.modify_configuration_code([:foo], :fake, true) + |> Igniter.Util.Debug.code_at_node() + + assert String.contains?(config, "config :fake, foo: true") + end + + test "update existing config" do + zipper = + ~s""" + import Config + config :fake, foo: [bar: "baz"] + """ + |> Sourceror.parse_string!() + |> Sourceror.Zipper.zip() + + config = + zipper + |> Igniter.Project.Config.modify_configuration_code([:foo], :fake, true, fn zipper -> + Igniter.Code.Keyword.put_in_keyword(zipper, [:bar], true) + end) + |> Igniter.Util.Debug.code_at_node() + + assert String.contains?(config, "config :fake, foo: [bar: true]") + end + end end