Skip to content

fix(jtk): use correct payload format for automation rule state endpoint#110

Merged
rianjs merged 1 commit intomainfrom
fix/105-automation-state-payload
Feb 8, 2026
Merged

fix(jtk): use correct payload format for automation rule state endpoint#110
rianjs merged 1 commit intomainfrom
fix/105-automation-state-payload

Conversation

@rianjs
Copy link
Copy Markdown
Contributor

@rianjs rianjs commented Feb 8, 2026

Summary

  • Change AutomationStateUpdate JSON field from "ruleState" to "value" to match the Automation REST API spec
  • The API expects {"value": "ENABLED"} but the code was sending {"ruleState": "ENABLED"}, causing a 400 Bad Request

Closes #105

Test plan

  • Test: enable sends {"value": "ENABLED"} (asserts raw JSON body)
  • Test: disable sends {"value": "DISABLED"} (asserts raw JSON body)
  • All existing automation tests pass

The Automation REST API expects {"value": "ENABLED"} but the code was
sending {"ruleState": "ENABLED"}, causing a 400 Bad Request. Updated
AutomationStateUpdate to use the "value" JSON field name per the
official API spec.

Closes #105
@rianjs
Copy link
Copy Markdown
Contributor Author

rianjs commented Feb 8, 2026

TDD Assessment

Summary

This PR fixes a payload format bug in SetAutomationRuleState. The Jira Automation REST API expects {"value": "ENABLED"} but the code was sending {"ruleState": "ENABLED"}, causing 400 Bad Request errors. The fix renames the struct field and JSON tag in AutomationStateUpdate, updates the call site, and strengthens the tests to assert on the raw JSON wire format rather than just the deserialized struct value.

All tests pass. TestSetAutomationRuleState (2 sub-tests) and all 3 command-layer TestRunSetState tests pass cleanly.

What's Covered

  • Wire-format assertion for enable: TestSetAutomationRuleState/enable captures the raw JSON body sent to the server and asserts it equals {"value":"ENABLED"}. This directly validates the fix.
  • Wire-format assertion for disable: TestSetAutomationRuleState/disable does the same for the disable path, asserting {"value":"DISABLED"}.
  • Test technique improvement: The old tests decoded the body into the AutomationStateUpdate struct and checked the field value. This was a tautological test -- if the struct definition was wrong, both serialization and deserialization would use the same wrong field name, and the test would still pass. The new tests capture json.RawMessage and use assert.JSONEq against a literal JSON string, which correctly catches field name mismatches.
  • Command-layer coverage: enable_test.go has 3 tests covering the runSetState function: already-enabled no-op, already-disabled no-op, and enable-a-disabled-rule (verifying GET + PUT request count). These were not changed in this PR but exercise the full code path through the fix.

What's Not Covered

  • HTTP method verification: The API-layer TestSetAutomationRuleState tests do not assert that the request is a PUT (vs POST or PATCH). The command-layer test (TestRunSetState_EnableDisabledRule) indirectly covers this by counting 2 requests (GET + PUT), but the API test itself does not check r.Method.
  • URL path verification: Neither API-layer test asserts that the request hits /rule/{id}/state. A typo in the URL format string would not be caught by these tests alone.
  • Error path: There is no test for SetAutomationRuleState when the server returns an error (e.g., 400, 500). The happy path is covered but failure handling is not tested at this layer.
  • ruleID escaping: The function uses url.PathEscape(ruleID) but there is no test with a rule ID containing special characters (e.g., slashes or spaces).

Verdict

Pass. The tests directly validate the bug fix by asserting the exact JSON wire format. The switch from struct-based decoding to raw JSON comparison is a meaningful improvement that would have caught the original bug. The gaps noted above (method/path/error assertions) are pre-existing and outside the scope of this fix.

@rianjs rianjs merged commit 2fe8909 into main Feb 8, 2026
7 checks passed
@rianjs rianjs deleted the fix/105-automation-state-payload branch February 8, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(jtk): automation enable/disable fails — API rejects ruleState payload

1 participant