Skip to content

Commit 1bd047e

Browse files
Merge pull request #174 from diffo-dev/62-characteristic-update_values-didnt-validate-typedstruct-fields
test case shows bug fixed
2 parents cdbbea4 + 9dcb673 commit 1bd047e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/provider/extension/characteristic_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule Diffo.Provider.Extension.CharacteristicTest do
77
use ExUnit.Case, async: true
88
@moduletag :domain_extended
99
alias Diffo.Test.Parties
10+
alias Diffo.Test.Servo
1011

1112
setup do
1213
AshNeo4j.Sandbox.checkout()
@@ -23,4 +24,34 @@ defmodule Diffo.Provider.Extension.CharacteristicTest do
2324
assert Diffo.Unwrap.unwrap(shelves) == []
2425
end
2526
end
27+
28+
# Regression coverage for issue #62 — invalid keys or invalid value types
29+
# supplied to a typed characteristic update must surface an error rather than
30+
# being silently dropped or persisted as-is.
31+
describe "typed characteristic update validation (#62)" do
32+
test "valid update succeeds" do
33+
{:ok, shelf} = Parties.build_shelf_with_installer()
34+
35+
updates = [shelf: [family: :ISAM, model: "EBLT48", technology: :adsl2Plus]]
36+
37+
assert {:ok, _} = Servo.define_shelf(shelf, %{characteristic_value_updates: updates})
38+
end
39+
40+
test "unknown field is rejected" do
41+
{:ok, shelf} = Parties.build_shelf_with_installer()
42+
43+
updates = [shelf: [family: :ISAM, cvc_id: "CVC-POI-SYD-001"]]
44+
45+
assert {:error, _} = Servo.define_shelf(shelf, %{characteristic_value_updates: updates})
46+
end
47+
48+
test "invalid value type is rejected" do
49+
{:ok, shelf} = Parties.build_shelf_with_installer()
50+
51+
# :family is :atom — a bare map cannot be cast to an atom
52+
updates = [shelf: [family: %{not: :an_atom}]]
53+
54+
assert {:error, _} = Servo.define_shelf(shelf, %{characteristic_value_updates: updates})
55+
end
56+
end
2657
end

0 commit comments

Comments
 (0)