@@ -77,22 +77,20 @@ assert_status "POST /api/orders returns 201" "201" "$STATUS"
7777
7878# Verify response shape (contract)
7979ORDER_ID=$( echo " $BODY " | json_field " ['id']" )
80- ORDER_TYPE=$( echo " $BODY " | json_field " ['type']" )
8180ORDER_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 "
8583assert_json_eq " Response has correct email" " test@example.com" " $ORDER_EMAIL "
8684
8785# ID has ord_ prefix
8886ID_PREFIX=$( echo " $ORDER_ID " | cut -c1-4)
8987assert_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)
9290if [ -n " $ORDER_CREATED " ] && [ " $ORDER_CREATED " != " None" ]; then
93- pass " Response has created_at timestamp"
91+ pass " Response has createdAt timestamp"
9492else
95- fail " Response missing created_at timestamp"
93+ fail " Response missing createdAt timestamp"
9694fi
9795
9896# ── Test 2: Get order by ID ─────────────────────────────────────────
@@ -129,11 +127,9 @@ BODY=$(echo "$BODY" | sed '$d')
129127assert_status " POST /api/payments returns 201" " 201" " $STATUS "
130128
131129PAYMENT_ID=$( echo " $BODY " | json_field " ['id']" )
132- PAYMENT_TYPE=$( echo " $BODY " | json_field " ['type']" )
133130PAYMENT_ORDER=$( echo " $BODY " | json_field " ['order_id']" )
134131PAYMENT_AMOUNT=$( echo " $BODY " | json_field " ['amount']" )
135132
136- assert_json_eq " Payment has type=payment" " payment" " $PAYMENT_TYPE "
137133assert_json_eq " Payment linked to correct order" " $ORDER_ID " " $PAYMENT_ORDER "
138134assert_json_eq " Payment has correct amount" " 4500" " $PAYMENT_AMOUNT "
139135
@@ -149,12 +145,13 @@ echo "--- List Orders ---"
149145BODY=$( 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
155151assert_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 ---"
164161BODY=$( 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 ']))" )
168165assert_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"
178175BODY=$( curl -s " $BASE_URL /api/orders/ord_nonexistent" )
179176assert_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
211180echo " "
0 commit comments