Skip to content

Commit 4d6111d

Browse files
committed
Fix nested screenshot app config parsing
1 parent 5484b01 commit 4d6111d

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/preflight_qa/screenshots.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ def append_optional_field(payload, key, options)
5151
private_class_method :append_optional_field
5252

5353
def normalize_apps(apps)
54-
raise ArgumentError, "apps must be a hash of app keys to mode arrays" unless apps.is_a?(Hash)
54+
raise ArgumentError, "apps must be a hash of app keys to mode hashes" unless apps.is_a?(Hash)
5555

56-
apps.each_with_object({}) do |(app, modes), normalized|
57-
normalized[app.to_s] = { modes: normalize_modes(modes) }
56+
apps.each_with_object({}) do |(app, config), normalized|
57+
normalized[app.to_s] = normalize_app_config(config)
5858
end
5959
end
6060
private_class_method :normalize_apps
6161

62+
def normalize_app_config(config)
63+
raise ArgumentError, "each app config must be a hash with :modes" unless config.is_a?(Hash)
64+
65+
modes = config[:modes] || config["modes"]
66+
raise ArgumentError, "each app config must include :modes" if modes.nil?
67+
68+
{ modes: normalize_modes(modes) }
69+
end
70+
private_class_method :normalize_app_config
71+
6272
def normalize_modes(modes)
6373
Array(modes).map(&:to_s)
6474
end

spec/preflight_qa/screenshots_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
result = described_class.create(
5353
subject: "My Test Email",
5454
html: "<html>test</html>",
55-
apps: { apple_mail_mac: [:light, :dark] },
55+
apps: { apple_mail_mac: { modes: [:light, :dark] } },
5656
webhook_url: "https://example.test/webhook",
5757
locale: "en-GB"
5858
)
@@ -77,6 +77,16 @@
7777
end.to raise_error(ArgumentError, /apps must be a hash/)
7878
end
7979

80+
it "raises when an app config does not include modes" do
81+
expect do
82+
described_class.create(
83+
subject: "My Test Email",
84+
html: "<html>test</html>",
85+
apps: { apple_mail_mac: {} }
86+
)
87+
end.to raise_error(ArgumentError, /must include :modes/)
88+
end
89+
8090
it "finds screenshots by uuid" do
8191
allow(client).to receive(:get)
8292
.with("/screenshots/1b153496-f702-4f89-85b4-cd1a9516cbbe")

0 commit comments

Comments
 (0)