Skip to content

Commit a4b5364

Browse files
test: Add regression tests for nested keyword config updates (#392)
1 parent b29e9d6 commit a4b5364

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

test/igniter/project/config_test.exs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,60 @@ defmodule Igniter.Project.ConfigTest do
1717
""")
1818
end
1919

20+
@tag :regression
21+
test "it updates nested keyword values in three argument config" do
22+
test_project()
23+
|> Igniter.create_new_file("config/dev.exs", """
24+
import Config
25+
config :demo, DemoWeb.Endpoint,
26+
http: [ip: {127, 0, 0, 1}, port: 4000],
27+
check_origin: false,
28+
code_reloader: true,
29+
debug_errors: true,
30+
secret_key_base: "A0DSgxjGCYZ6fCIrBlg6L+qC/cdoFq5Rmomm53yacVmN95Wcpl57Gv0sTJjKjtIp",
31+
watchers: [
32+
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
33+
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
34+
]
35+
""")
36+
|> apply_igniter!()
37+
|> Igniter.Project.Config.configure(
38+
"dev.exs",
39+
:demo,
40+
[DemoWeb.Endpoint, :http, :port],
41+
{:code, Sourceror.parse_string!("4100")}
42+
)
43+
|> assert_has_patch("config/dev.exs", """
44+
4 - | http: [ip: {127, 0, 0, 1}, port: 4000],
45+
4 + | http: [ip: {127, 0, 0, 1}, port: 4100],
46+
""")
47+
end
48+
49+
@tag :regression
50+
test "it only updates the matching config when another config has the same nested key" do
51+
test_project()
52+
|> Igniter.create_new_file("config/dev.exs", """
53+
import Config
54+
55+
config :demo, OtherWeb.Endpoint,
56+
http: [ip: {127, 0, 0, 1}, port: 4000]
57+
58+
config :demo, DemoWeb.Endpoint,
59+
http: [ip: {127, 0, 0, 1}, port: 4000]
60+
""")
61+
|> apply_igniter!()
62+
|> Igniter.Project.Config.configure(
63+
"dev.exs",
64+
:demo,
65+
[DemoWeb.Endpoint, :http, :port],
66+
{:code, Sourceror.parse_string!("4100")}
67+
)
68+
|> assert_has_patch("config/dev.exs", """
69+
5 - |config :demo, DemoWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4000]
70+
5 + |config :demo, DemoWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4100]
71+
""")
72+
end
73+
2074
test "it doesn't modify a file if the updater returns an error" do
2175
igniter =
2276
test_project(

0 commit comments

Comments
 (0)