Skip to content

test(booking): assert persisted state and fail on leaked cleanup - #3

Merged
VincentJerico merged 2 commits into
mainfrom
test/assert-persisted-state
Oct 20, 2026
Merged

VincentJerico merged 2 commits into
mainfrom
test/assert-persisted-state

Conversation

@VincentJerico

@VincentJerico VincentJerico commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Why

Run against a local Restful-Booker mock with each defect below switched on, the suite still passed 16/16:

  • PUT and PATCH returned the right echo without saving. The tests never read the booking back.
  • An invalid-token PUT returned 403 but still applied the write. The test checked the status only.
  • A malformed create stored a partial row. The test accepted any status of 400 or above.
  • GET /booking returned []. The list contract accepts an empty list.
  • Cleanup DELETEs returned 403. cleanup() swallowed that and leaked 9 bookings, which contradicts the README's promise that tests never leak data.

Scope

  • CRUD and negative specs GET the booking after each write and assert the full stored booking.
  • The malformed-create test pins the 500 the README already documents, with an issue annotation. It then proves nothing was stored by creating a valid booking under the same unique name and asserting the name filter returns only that booking.
  • The list contract asserts the list contains a booking it just created. It doesn't use .nonempty(), which would depend on other users' data.
  • BookingClient.cleanup() throws after the loop if any booking it created is still there. When a DELETE fails, a GET decides: Restful-Booker answers DELETE on a missing booking with 405, not 404, so the status code alone can't tell.
  • A regression test deletes a booking behind the client's back, the way the demo's periodic reset does, and requires cleanup() to succeed.
  • list() takes an optional { firstname } filter.

Verification

  • Every mock defect above passes 16/16 on main and turns its test red on this branch. The cleanup defect fails with "cleanup could not delete bookings".
  • The regression test failed with "cleanup could not delete bookings: " before the GET check. A booking that really survives still makes cleanup() throw.
  • lint, format and typecheck are clean. The live suite passes 17/17.

… cleanup

PUT, PATCH and the invalid-token write only checked the response, so a server
that echoed the body without saving it passed. They now read the booking back.
The malformed-create test pins the documented 500 and checks nothing was stored,
with a valid booking under the same name proving the filter works.
The list contract test now looks for a booking it just created.
Missing credentials now get the same failure-schema check as bad credentials.
cleanup() swallowed failed deletes and leaked bookings onto the shared demo.
It now fails teardown and names the bookings it could not remove.
cleanup() treated a 404 on DELETE as "already gone", but Restful-Booker
answers DELETE on a missing booking with 405 (GET returns 404). A
booking wiped by the demo API's periodic reset therefore made cleanup
throw and fail the test in teardown with no real leak.

When DELETE doesn't succeed, cleanup now asks GET: 404 means gone,
anything else still counts as leaked.

Adds a regression test that deletes a booking behind the client's back
and requires cleanup() to succeed. It failed before this change with
"cleanup could not delete bookings: <id>".
@VincentJerico
VincentJerico merged commit 5587638 into main Oct 20, 2026
2 checks passed
@VincentJerico
VincentJerico deleted the test/assert-persisted-state branch October 20, 2026 01:05
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