@@ -42,7 +42,26 @@ defmodule Statifier.Actions.AssignActionTest do
4242 assert % StateChart { datamodel: % { "userName" => "John Doe" } } = result
4343 end
4444
45- test "executes nested assignment" , % { state_chart: state_chart } do
45+ test "fails nested assignment when intermediate structures don't exist" , % {
46+ state_chart: state_chart
47+ } do
48+ action = AssignAction . new ( "user.profile.name" , "'Jane Smith'" )
49+
50+ result = AssignAction . execute ( state_chart , action )
51+
52+ # Should fail and generate error.execution event
53+ assert result . internal_queue |> length ( ) == 1
54+ [ error_event ] = result . internal_queue
55+ assert error_event . name == "error.execution"
56+ assert error_event . data [ "type" ] == "assign.execution"
57+ assert error_event . data [ "location" ] == "user.profile.name"
58+ end
59+
60+ test "executes nested assignment when intermediate structures exist" , % {
61+ state_chart: state_chart
62+ } do
63+ # Set up intermediate structures first
64+ state_chart = % { state_chart | datamodel: % { "user" => % { "profile" => % { } } } }
4665 action = AssignAction . new ( "user.profile.name" , "'Jane Smith'" )
4766
4867 result = AssignAction . execute ( state_chart , action )
@@ -60,12 +79,29 @@ defmodule Statifier.Actions.AssignActionTest do
6079 assert % StateChart { datamodel: % { "counter" => 8 } } = result
6180 end
6281
63- test "executes assignment with mixed notation" , % { state_chart: state_chart } do
82+ test "fails assignment with mixed notation when intermediate structures don't exist" , % {
83+ state_chart: state_chart
84+ } do
6485 state_chart = % { state_chart | datamodel: % { "users" => % { } } }
6586 action = AssignAction . new ( "users['john'].active" , "true" )
6687
6788 result = AssignAction . execute ( state_chart , action )
6889
90+ # Should fail and generate error.execution event because users['john'] doesn't exist
91+ assert result . internal_queue |> length ( ) == 1
92+ [ error_event ] = result . internal_queue
93+ assert error_event . name == "error.execution"
94+ assert error_event . data [ "type" ] == "assign.execution"
95+ end
96+
97+ test "executes assignment with mixed notation when intermediate structures exist" , % {
98+ state_chart: state_chart
99+ } do
100+ state_chart = % { state_chart | datamodel: % { "users" => % { "john" => % { } } } }
101+ action = AssignAction . new ( "users['john'].active" , "true" )
102+
103+ result = AssignAction . execute ( state_chart , action )
104+
69105 expected_data = % { "users" => % { "john" => % { "active" => true } } }
70106 assert % StateChart { datamodel: ^ expected_data } = result
71107 end
@@ -152,9 +188,27 @@ defmodule Statifier.Actions.AssignActionTest do
152188 assert log_entry . metadata . location == "result"
153189 end
154190
155- test "assigns complex data structures" , % { state_chart: state_chart } do
156- # This would work with enhanced expression evaluation that supports object literals
157- # For now, we test with a simple string that predictor can handle
191+ test "fails to assign complex data structures when intermediate structures don't exist" , % {
192+ state_chart: state_chart
193+ } do
194+ # Assignment to config.settings should fail because config doesn't exist
195+ action = AssignAction . new ( "config.settings" , "'complex_value'" )
196+
197+ result = AssignAction . execute ( state_chart , action )
198+
199+ # Should fail and generate error.execution event
200+ assert result . internal_queue |> length ( ) == 1
201+ [ error_event ] = result . internal_queue
202+ assert error_event . name == "error.execution"
203+ assert error_event . data [ "type" ] == "assign.execution"
204+ assert error_event . data [ "location" ] == "config.settings"
205+ end
206+
207+ test "assigns complex data structures when intermediate structures exist" , % {
208+ state_chart: state_chart
209+ } do
210+ # Set up intermediate structure first
211+ state_chart = % { state_chart | datamodel: % { "config" => % { } } }
158212 action = AssignAction . new ( "config.settings" , "'complex_value'" )
159213
160214 result = AssignAction . execute ( state_chart , action )
@@ -187,20 +241,24 @@ defmodule Statifier.Actions.AssignActionTest do
187241 assert action . expr == "'John Doe'"
188242 end
189243
190- test "expressions work correctly with validation-time compilation" , % {
191- state_chart: state_chart
192- } do
244+ test "expressions work correctly with validation-time compilation - fails when intermediate structures don't exist" ,
245+ % {
246+ state_chart: state_chart
247+ } do
193248 action = AssignAction . new ( "user.settings.theme" , "'dark'" )
194249
195250 # Verify expression is not compiled during creation
196251 assert is_nil ( action . compiled_expr )
197252
198- # Execute should work with runtime compilation as fallback
253+ # Execute should fail because user doesn't exist
199254 result = AssignAction . execute ( state_chart , action )
200255
201- # Verify result is correct
202- expected_data = % { "user" => % { "settings" => % { "theme" => "dark" } } }
203- assert % StateChart { datamodel: ^ expected_data } = result
256+ # Should fail and generate error.execution event
257+ assert result . internal_queue |> length ( ) == 1
258+ [ error_event ] = result . internal_queue
259+ assert error_event . name == "error.execution"
260+ assert error_event . data [ "type" ] == "assign.execution"
261+ assert error_event . data [ "location" ] == "user.settings.theme"
204262 end
205263 end
206264end
0 commit comments