Skip to content

Send Submit an Inspection's rewritten body as JSON - #61

Open
roncodes wants to merge 1 commit into
mainfrom
fix/submit-inspection-json-body
Open

Send Submit an Inspection's rewritten body as JSON#61
roncodes wants to merge 1 commit into
mainfrom
fix/submit-inspection-json-body

Conversation

@roncodes

Copy link
Copy Markdown
Member

Summary

"Submit an Inspection" has failed every contract run since postman#60 merged. Its body arrived at the API empty.

The request's pre-request script rebuilds the body to add custom_field_values, which name fields by the ids "Retrieve an Inspection Form" read. pm.request.body.update({ mode: "raw", raw: ... }) replaces the body wholesale, including the raw json language, so the rebuilt body went out as text/plain. Laravel parsed none of it and refused every field as missing:

422 {"errors":{"custom_field_values":["...required when item results is not present."],"item_results":[...],"inspection_form":["The inspection form field is required."],"driver":["The driver field is required."]}}

In the contract run's output it was the only one of 120 write requests sent as ↑ text; the other 117 went as ↑ json. Before fleetbase/fleetops#319 made inspection routes answer in JSON, the same refusal came back as a redirect, which the runner followed to a port nothing listens on and reported as ECONNREFUSED. "Retrieve an Inspection" then 404s because nothing was filed.

Change

  • The rewrite restates the language: pm.request.body.update({ mode: "raw", raw, options: { raw: { language: "json" } } }).
  • It also sets Content-Type: application/json explicitly, so the header doesn't depend on the language being carried over.
  • The request asks for Accept: application/json, so a refusal is always a readable 422.

No other request in the collection rewrites its body this way.

Related Issue

Follows #60. Unblocks the Postman contract check on fleetbase/fleetops#319, which runs the collection at postman-ref: main.

Type of Change

  • Bug fix

Validation

  • Lint
  • Manual validation against a live stack

scripts/validate-collections.js and postman collection lint pass, and the pre-request script passes node --check. Against a local FleetOps test harness, the same payload sent as JSON files the inspection: all three field values are stored, and the photo and the signature come back as files with URLs, which is what the request's assertions check. It has not been run against the CI stack; the next contract run on fleetops#319 after this merges will do that.

Risk

Low. One request's pre-request script and headers.

The pre-request script rebuilds the body to add custom_field_values, and
pm.request.body.update() replaced it without its raw language. The body
went out as text/plain, the API parsed none of it, and answered that every
field was missing: a 422 once fleetops#319 answers inspection routes in
JSON, and before that a redirect the runner reported as ECONNREFUSED. It
was the only one of 120 write requests in the contract run sent as text.

The rewrite now restates the JSON language and sets Content-Type, and the
request asks for application/json.
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.

1 participant