Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion postman/collections/Fleetbase API/.resources/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ scripts:
// started returning a document would still be caught.
const contentType = pm.response.headers.get('Content-Type') || '';
const isDocument = /^(application\/pdf|image\/|application\/octet-stream|text\/csv)/i.test(contentType);
const expected = pm.request.method === "POST" ? [200, 201, 202] : [200, 201, 202, 204];

// A request whose documented answer is not 2xx (Update Order Activity on an order
// whose flow is already complete must answer 400) opts out of the 2xx expectation
// by setting `expected_status` in its own beforeRequest script. The variable is
// consumed here, so it never leaks into the next request.
const expectedOverride = Number(pm.variables.get('expected_status')) || null;
pm.variables.unset('expected_status');
const expected = expectedOverride
? [expectedOverride]
: (pm.request.method === "POST" ? [200, 201, 202] : [200, 201, 202, 204]);

if (isDocument) {
// Still asserted, not excused: a document response must carry actual bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ body:
type: json
content: ""
scripts:
- type: beforeRequest
code: |-
// A contract run cycles this request with Update Order Activity more times than an
// order can need, since how many activities a flow takes is not known up front. Once
// the flow is exhausted there is nothing left to look up, so the surplus passes are
// skipped rather than sent: a skipped request is neither a pass nor a failure.
if (pm.environment.get('order_flow_exhausted')) {
pm.execution.skipRequest();
}
language: text/javascript
- type: afterResponse
code: |-
// The response is the list of activities available from the order's current point in
Expand All @@ -34,10 +24,14 @@ scripts:
pm.environment.set("next_activity", JSON.stringify(json_response[0]));
} else {
// An empty list means the order has reached the end of its flow: applying the
// last activity completed it. Update Order Activity would now answer 400
// "Order is already completed.", so the cycle stops here.
// last activity completed it. A contract run cycles this request with Update
// Order Activity more times than an order can need, since how many activities
// a flow takes is not known up front; from here on Update Order Activity
// expects the 400 "Order is already completed." refusal. (A skipped request —
// pm.execution.skipRequest — is counted as an error by the Postman CLI, so the
// surplus passes are sent and asserted rather than skipped.) The last activity
// is kept so the body stays valid JSON.
pm.environment.set("order_flow_exhausted", "true");
pm.environment.unset("next_activity");
}
language: text/javascript
examples: ./.resources/Get Order Next Activity.resources/examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ body:
scripts:
- type: beforeRequest
code: |-
// Nothing to apply once Get Order Next Activity found the flow exhausted: the body
// would not be JSON, and the API refuses a completed order with 400 "Order is
// already completed." Skipped, not failed — see Get Order Next Activity.
if (pm.environment.get('order_flow_exhausted') || !pm.environment.get('next_activity')) {
pm.execution.skipRequest();
// Once Get Order Next Activity found the flow exhausted, the order is complete and
// the API refuses further activity with 400 "Order is already completed." — the
// documented answer, so the surplus passes of the contract run's cycle assert it.
if (pm.environment.get('order_flow_exhausted')) {
pm.variables.set('expected_status', 400);
}
language: text/javascript
- type: afterResponse
Expand Down
Loading