Skip to content

Commit 9dfbbfa

Browse files
committed
chore: Update filter body syntax in documentation and tests for consistency
1 parent 41ca272 commit 9dfbbfa

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CLI: --rule-retry-strategy exponential --rule-filter-body '{...}'
8585
# Retry → Filter → Transform execution order
8686
hookdeck connection create \
8787
--rule-retry-strategy exponential --rule-retry-count 3 \
88-
--rule-filter-body '{\"$.event_type\":\"payment\"}' \
88+
--rule-filter-body '{"event_type":"payment"}' \
8989
--rule-transform-name "my-transform"
9090

9191
# JSON fallback for complex configurations
@@ -354,7 +354,7 @@ hookdeck connection upsert my-connection
354354
Connection 'my-connection' (conn_123) will be updated with the following changes:
355355
- Description: "New description"
356356
- Rules: (ruleset will be replaced)
357-
- Filter: body contains '{"$.type":"payment"}'
357+
- Filter: body contains '{"type":"payment"}'
358358
```
359359
360360
**Implementation Strategy:**

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ $ hookdeck connection create \
625625
--destination-name "processor" \
626626
--destination-type HTTP \
627627
--destination-url "https://api.example.com/process" \
628-
--rule-filter-body '{"$.event_type":"payment.succeeded"}'
628+
--rule-filter-body '{"event_type":"payment.succeeded"}'
629629

630630
# Combined filtering
631631
$ hookdeck connection create \
@@ -634,7 +634,7 @@ $ hookdeck connection create \
634634
--destination-name "order-processor" \
635635
--destination-type HTTP \
636636
--destination-url "https://api.example.com/orders" \
637-
--rule-filter-body '{"$.type":"order"}' \
637+
--rule-filter-body '{"type":"order"}' \
638638
--rule-retry-strategy exponential \
639639
--rule-retry-count 3
640640
```

REFERENCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ hookdeck connection create \
10291029
--destination-name "processor" \
10301030
--destination-type HTTP \
10311031
--destination-url "https://api.example.com/process" \
1032-
--rule-filter-body '{"$.event_type":"payment.succeeded"}'
1032+
--rule-filter-body '{"event_type":"payment.succeeded"}'
10331033
```
10341034

10351035
**8. All Rule Types Combined**
@@ -1040,7 +1040,7 @@ hookdeck connection create \
10401040
--destination-name "order-processor" \
10411041
--destination-type HTTP \
10421042
--destination-url "https://api.example.com/orders" \
1043-
--rule-filter-body '{"$.type":"order"}' \
1043+
--rule-filter-body '{"type":"order"}' \
10441044
--rule-retry-strategy exponential \
10451045
--rule-retry-count 3 \
10461046
--rule-retry-interval 30000 \

test/acceptance/connection_test.go

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ func TestConnectionWithFilterRule(t *testing.T) {
782782
"--destination-name", destName,
783783
"--destination-type", "CLI",
784784
"--destination-cli-path", "/webhooks",
785-
"--rule-filter-body", `{"$.type":"payment"}`,
786-
"--rule-filter-headers", `{"$.content-type":"application/json"}`,
785+
"--rule-filter-body", `{"type":"payment"}`,
786+
"--rule-filter-headers", `{"content-type":"application/json"}`,
787787
)
788788
require.NoError(t, err, "Should create connection with filter rule")
789789
require.NotEmpty(t, conn.ID, "Connection should have an ID")
@@ -803,8 +803,8 @@ func TestConnectionWithFilterRule(t *testing.T) {
803803

804804
rule := getConn.Rules[0]
805805
assert.Equal(t, "filter", rule["type"], "Rule type should be filter")
806-
assert.Equal(t, `{"$.type":"payment"}`, rule["body"], "Filter body should match input")
807-
assert.Equal(t, `{"$.content-type":"application/json"}`, rule["headers"], "Filter headers should match input")
806+
assert.Equal(t, `{"type":"payment"}`, rule["body"], "Filter body should match input")
807+
assert.Equal(t, `{"content-type":"application/json"}`, rule["headers"], "Filter headers should match input")
808808

809809
t.Logf("Successfully created and verified connection with filter rule: %s", conn.ID)
810810
}
@@ -987,7 +987,7 @@ func TestConnectionWithMultipleRules(t *testing.T) {
987987
"--destination-name", destName,
988988
"--destination-type", "CLI",
989989
"--destination-cli-path", "/webhooks",
990-
"--rule-filter-body", `{"$.type":"payment"}`,
990+
"--rule-filter-body", `{"type":"payment"}`,
991991
"--rule-retry-strategy", "exponential",
992992
"--rule-retry-count", "5",
993993
"--rule-retry-interval", "60000",
@@ -1015,7 +1015,7 @@ func TestConnectionWithMultipleRules(t *testing.T) {
10151015
assert.Equal(t, "retry", getConn.Rules[2]["type"], "Third rule should be retry (logical order)")
10161016

10171017
// Verify filter rule details
1018-
assert.Equal(t, `{"$.type":"payment"}`, getConn.Rules[0]["body"], "Filter should have body expression")
1018+
assert.Equal(t, `{"type":"payment"}`, getConn.Rules[0]["body"], "Filter should have body expression")
10191019

10201020
// Verify delay rule details
10211021
assert.Equal(t, float64(1000), getConn.Rules[1]["delay"], "Delay should be 1000 milliseconds")
@@ -1535,7 +1535,7 @@ func TestConnectionUpsertReplaceRules(t *testing.T) {
15351535
assert.Equal(t, "retry", initialRule["type"], "Initial rule should be retry type")
15361536

15371537
// Upsert to REPLACE retry rule with filter rule (using proper JSON format)
1538-
filterBody := `{"$.type":"payment"}`
1538+
filterBody := `{"type":"payment"}`
15391539
var upserted Connection
15401540
err = cli.RunJSON(&upserted,
15411541
"connection", "upsert", connName,
@@ -1591,3 +1591,62 @@ func TestConnectionUpsertValidation(t *testing.T) {
15911591

15921592
t.Logf("Successfully verified validation errors")
15931593
}
1594+
1595+
// TestConnectionCreateOutputStructure tests the human-readable output format
1596+
func TestConnectionCreateOutputStructure(t *testing.T) {
1597+
if testing.Short() {
1598+
t.Skip("Skipping acceptance test in short mode")
1599+
}
1600+
1601+
cli := NewCLIRunner(t)
1602+
timestamp := generateTimestamp()
1603+
1604+
connName := "test-output-" + timestamp
1605+
sourceName := "test-src-output-" + timestamp
1606+
destName := "test-dst-output-" + timestamp
1607+
1608+
// Create connection without --output json to get human-readable format
1609+
stdout := cli.RunExpectSuccess(
1610+
"connection", "create",
1611+
"--name", connName,
1612+
"--source-name", sourceName,
1613+
"--source-type", "WEBHOOK",
1614+
"--destination-name", destName,
1615+
"--destination-type", "CLI",
1616+
"--destination-cli-path", "/webhooks",
1617+
)
1618+
1619+
// Parse connection ID from output for cleanup (it appears in multiple places)
1620+
// Look for pattern "Successfully created connection with ID: conn_xxxxx"
1621+
lines := strings.Split(stdout, "\n")
1622+
var connID string
1623+
for _, line := range lines {
1624+
if strings.Contains(line, "Successfully created connection with ID:") {
1625+
parts := strings.Split(line, ":")
1626+
if len(parts) >= 2 {
1627+
connID = strings.TrimSpace(parts[1])
1628+
break
1629+
}
1630+
}
1631+
}
1632+
require.NotEmpty(t, connID, "Should be able to parse connection ID from output")
1633+
1634+
// Cleanup
1635+
t.Cleanup(func() {
1636+
deleteConnection(t, cli, connID)
1637+
})
1638+
1639+
// Verify output structure contains expected elements from create command
1640+
assert.Contains(t, stdout, "Successfully created connection with ID:", "Should show success message")
1641+
assert.Contains(t, stdout, "Connection:", "Should show Connection label")
1642+
assert.Contains(t, stdout, connName, "Should include connection name")
1643+
assert.Contains(t, stdout, connID, "Should include connection ID")
1644+
assert.Contains(t, stdout, "Source:", "Should show Source label")
1645+
assert.Contains(t, stdout, sourceName, "Should include source name")
1646+
assert.Contains(t, stdout, "Source URL:", "Should show source URL label")
1647+
assert.Contains(t, stdout, "https://hkdk.events/", "Should include Hookdeck event URL")
1648+
assert.Contains(t, stdout, "Destination:", "Should show Destination label")
1649+
assert.Contains(t, stdout, destName, "Should include destination name")
1650+
1651+
t.Logf("Successfully verified connection create output structure")
1652+
}

0 commit comments

Comments
 (0)