Skip to content

Commit 51d08f8

Browse files
committed
fix(ci): download API specs in CI, fix test assertions for statefulBinding
- CI workflow: add spec download step for Stripe/Twilio/OpenAI (specs are gitignored, must be fetched from upstream repos) - ci-testing/test.sh: remove type field checks (no response transforms), fix createdAt field name, fix list envelope (data not orders), remove mockd verify (no named mock IDs in statefulBinding configs) - microservices/test.sh: fix seed data counts (2 not 3), fix post-create counts
1 parent 9b3c32a commit 51d08f8

3 files changed

Lines changed: 34 additions & 45 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ jobs:
8888
env:
8989
GH_TOKEN: ${{ github.token }}
9090

91+
- name: Download API specs
92+
run: |
93+
case "${{ matrix.sample.name }}" in
94+
stripe)
95+
curl -sf -L -o third-party-apis/stripe-api/stripe.yaml \
96+
"https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.yaml"
97+
echo "Downloaded Stripe spec ($(wc -c < third-party-apis/stripe-api/stripe.yaml) bytes)"
98+
;;
99+
twilio)
100+
curl -sf -L -o third-party-apis/twilio-api/twilio.json \
101+
"https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json"
102+
echo "Downloaded Twilio spec ($(wc -c < third-party-apis/twilio-api/twilio.json) bytes)"
103+
;;
104+
openai)
105+
curl -sf -L -o third-party-apis/openai-api/openai.yaml \
106+
"https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml"
107+
echo "Downloaded OpenAI spec ($(wc -c < third-party-apis/openai-api/openai.yaml) bytes)"
108+
;;
109+
esac
110+
91111
- name: Start mockd with config
92112
run: |
93113
mockd start -c ${{ matrix.sample.config }} --no-auth -d

ci-testing/github-actions/test.sh

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,20 @@ assert_status "POST /api/orders returns 201" "201" "$STATUS"
7777

7878
# Verify response shape (contract)
7979
ORDER_ID=$(echo "$BODY" | json_field "['id']")
80-
ORDER_TYPE=$(echo "$BODY" | json_field "['type']")
8180
ORDER_EMAIL=$(echo "$BODY" | json_field "['customer_email']")
82-
ORDER_CREATED=$(echo "$BODY" | json_field "['created_at']")
81+
ORDER_CREATED=$(echo "$BODY" | json_field "['createdAt']")
8382

84-
assert_json_eq "Response has type=order" "order" "$ORDER_TYPE"
8583
assert_json_eq "Response has correct email" "test@example.com" "$ORDER_EMAIL"
8684

8785
# ID has ord_ prefix
8886
ID_PREFIX=$(echo "$ORDER_ID" | cut -c1-4)
8987
assert_json_eq "Order ID has ord_ prefix" "ord_" "$ID_PREFIX"
9088

91-
# created_at is present (ISO 8601 timestamp)
89+
# createdAt is present (ISO 8601 timestamp)
9290
if [ -n "$ORDER_CREATED" ] && [ "$ORDER_CREATED" != "None" ]; then
93-
pass "Response has created_at timestamp"
91+
pass "Response has createdAt timestamp"
9492
else
95-
fail "Response missing created_at timestamp"
93+
fail "Response missing createdAt timestamp"
9694
fi
9795

9896
# ── Test 2: Get order by ID ─────────────────────────────────────────
@@ -129,11 +127,9 @@ BODY=$(echo "$BODY" | sed '$d')
129127
assert_status "POST /api/payments returns 201" "201" "$STATUS"
130128

131129
PAYMENT_ID=$(echo "$BODY" | json_field "['id']")
132-
PAYMENT_TYPE=$(echo "$BODY" | json_field "['type']")
133130
PAYMENT_ORDER=$(echo "$BODY" | json_field "['order_id']")
134131
PAYMENT_AMOUNT=$(echo "$BODY" | json_field "['amount']")
135132

136-
assert_json_eq "Payment has type=payment" "payment" "$PAYMENT_TYPE"
137133
assert_json_eq "Payment linked to correct order" "$ORDER_ID" "$PAYMENT_ORDER"
138134
assert_json_eq "Payment has correct amount" "4500" "$PAYMENT_AMOUNT"
139135

@@ -149,12 +145,13 @@ echo "--- List Orders ---"
149145
BODY=$(curl -s "$BASE_URL/api/orders")
150146

151147
# Seed data has 2 orders + we created 1 = 3
152-
ORDER_COUNT=$(echo "$BODY" | json_field "['total_count']")
153-
ORDERS_LEN=$(echo "$BODY" | python3 -c "import json,sys; print(len(json.load(sys.stdin)['orders']))")
148+
ORDERS_LEN=$(echo "$BODY" | python3 -c "import json,sys; print(len(json.load(sys.stdin)['data']))")
149+
ORDER_TOTAL=$(echo "$BODY" | json_field "['meta']['total']")
154150

155151
assert_json_eq "List orders returns 3 items" "3" "$ORDERS_LEN"
156-
assert_contains "List response has 'orders' array" '"orders"' "$BODY"
157-
assert_contains "List response has total_count" '"total_count"' "$BODY"
152+
assert_json_eq "List meta.total is 3" "3" "$ORDER_TOTAL"
153+
assert_contains "List response has 'data' array" '"data"' "$BODY"
154+
assert_contains "List response has meta" '"meta"' "$BODY"
158155

159156
# ── Test 5: List payments ────────────────────────────────────────────
160157

@@ -164,7 +161,7 @@ echo "--- List Payments ---"
164161
BODY=$(curl -s "$BASE_URL/api/payments")
165162

166163
# Seed data has 2 payments + we created 1 = 3
167-
PAYMENTS_LEN=$(echo "$BODY" | python3 -c "import json,sys; print(len(json.load(sys.stdin)['payments']))")
164+
PAYMENTS_LEN=$(echo "$BODY" | python3 -c "import json,sys; print(len(json.load(sys.stdin)['data']))")
168165
assert_json_eq "List payments returns 3 items" "3" "$PAYMENTS_LEN"
169166

170167
# ── Test 6: Get nonexistent resource returns 404 ─────────────────────
@@ -178,34 +175,6 @@ assert_status "GET nonexistent order returns 404" "404" "$STATUS"
178175
BODY=$(curl -s "$BASE_URL/api/orders/ord_nonexistent")
179176
assert_contains "404 response has error message" '"message"' "$BODY"
180177

181-
# ── Test 7: Verify mock invocations (contract checks) ────────────────
182-
183-
echo ""
184-
echo "--- Contract Verification ---"
185-
186-
# These checks ensure your test suite actually exercises the API contract.
187-
# In CI, failing verification means your tests have coverage gaps.
188-
189-
mockd verify check orders-create --at-least 1 2>/dev/null && \
190-
pass "orders-create was called at least once" || \
191-
fail "orders-create was NOT called (contract gap)"
192-
193-
mockd verify check orders-list --at-least 1 2>/dev/null && \
194-
pass "orders-list was called at least once" || \
195-
fail "orders-list was NOT called (contract gap)"
196-
197-
mockd verify check orders-get --at-least 1 2>/dev/null && \
198-
pass "orders-get was called at least once" || \
199-
fail "orders-get was NOT called (contract gap)"
200-
201-
mockd verify check payments-create --at-least 1 2>/dev/null && \
202-
pass "payments-create was called at least once" || \
203-
fail "payments-create was NOT called (contract gap)"
204-
205-
mockd verify check payments-list --at-least 1 2>/dev/null && \
206-
pass "payments-list was called at least once" || \
207-
fail "payments-list was NOT called (contract gap)"
208-
209178
# ── Results ──────────────────────────────────────────────────────────
210179

211180
echo ""

microservices/docker-compose/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ RESPONSE=$(curl -s -w "\n%{http_code}" "$BASE_URL/users")
7272
STATUS=$(echo "$RESPONSE" | tail -1)
7373
BODY=$(echo "$RESPONSE" | sed '$d')
7474
assert_status "list users" "200" "$STATUS"
75-
assert_json_field "seed data present" "$BODY" '.data | length' "3"
75+
assert_json_field "seed data present" "$BODY" '.data | length' "2"
7676
assert_json_field "first user name" "$BODY" '.data[0].name' "Alice Johnson"
7777

7878
# Get user by ID
@@ -101,7 +101,7 @@ RESPONSE=$(curl -s -w "\n%{http_code}" "$BASE_URL/users")
101101
STATUS=$(echo "$RESPONSE" | tail -1)
102102
BODY=$(echo "$RESPONSE" | sed '$d')
103103
assert_status "list after create" "200" "$STATUS"
104-
assert_json_field "count increased" "$BODY" '.data | length' "4"
104+
assert_json_field "count increased" "$BODY" '.data | length' "3"
105105

106106
# Get the newly created user
107107
bold " GET /users/$NEW_USER_ID (get created)"
@@ -123,7 +123,7 @@ RESPONSE=$(curl -s -w "\n%{http_code}" "$BASE_URL/payments")
123123
STATUS=$(echo "$RESPONSE" | tail -1)
124124
BODY=$(echo "$RESPONSE" | sed '$d')
125125
assert_status "list payments" "200" "$STATUS"
126-
assert_json_field "seed data present" "$BODY" '.data | length' "3"
126+
assert_json_field "seed data present" "$BODY" '.data | length' "2"
127127
assert_json_field "first payment status" "$BODY" '.data[0].status' "completed"
128128

129129
# Get payment by ID
@@ -154,7 +154,7 @@ RESPONSE=$(curl -s -w "\n%{http_code}" "$BASE_URL/payments")
154154
STATUS=$(echo "$RESPONSE" | tail -1)
155155
BODY=$(echo "$RESPONSE" | sed '$d')
156156
assert_status "list after create" "200" "$STATUS"
157-
assert_json_field "count increased" "$BODY" '.data | length' "4"
157+
assert_json_field "count increased" "$BODY" '.data | length' "3"
158158

159159
# Get the newly created payment
160160
bold " GET /payments/$NEW_PAY_ID (get created)"

0 commit comments

Comments
 (0)