Skip to content

Latest commit

 

History

History
100 lines (91 loc) · 11 KB

test-hooks.md

File metadata and controls

100 lines (91 loc) · 11 KB

Test hooks

With TEST_HOOKS=1 (the default in compose.yaml) the app mounts a test-only API. Every hook is scoped to one sandbox, so parallel tests never see each other.

Endpoint Effect
POST /api/sandboxes Creates a sandbox; returns { id }. Not a hook: visitors use it too.
POST /__test__/s/:id/reset Deletes messages, restores the four default cards, removes export jobs, clears faults, flags, settings, the playlist order, the wallet and card tokens, the draft, the calendar connection, the contacts, the bookings, the feed, the checklist, the vault and its clock, support messages, mail, sessions, the cart, and orders, restores the default reviews, and closes the sandbox's sockets.
POST /__test__/s/:id/seed { messages: [{ name, text }] } stores and broadcasts messages; { cards: [{ title, description?, status? }] } replaces all cards.
POST /__test__/s/:id/fault See below.
POST /__test__/s/:id/flags { createCard: "inline" | "dialog" | null } pins the create-card variant for the sandbox. { draw: "inline" | "dialog" | null } fixes the variant a visitor without a stored assignment is assigned; null draws at random. Send either key or both; a key you leave out keeps its value.
POST /__test__/s/:id/clock { nowMs } sets the sandbox's server time for the Vault (codes and lockout); { nowMs: null } returns to the real time.
GET /__test__/s/:id/vault-code { code }: the Vault's code for the sandbox's current server time.
POST /__test__/s/:id/expire-sessions Marks every session of the sandbox as expired on the server; the cookies stay in the browser.
POST /__test__/s/:id/login { email } signs in without mail; returns the session cookie { name, value } and sets it.

fault accepts any of:

Field Effect
dropSockets: "<name>" | "all" Closes those sockets with code 4001.
broadcastDelayMs Delays chat broadcasts.
http: [{ method, path, status?, delayMs?, times?, always? }] Later API requests matching method and path (relative to /api/s/:id, * matches one segment, e.g. cards/*) wait delayMs and, with status, fail with that status without running. Each rule applies times times (default 1), or forever with always: true.
exports: { stepMs?, failAtStep?, failRuns? } Export step length (default 500 ms), and the step at which the next failRuns exports (default 1) fail.
auth: { tokenTtlMs } Lifetime of sign-in links requested afterwards (default 10 minutes).

Hooks for one case

Each of these serves one case; the case file says how its tests use it. Paths are relative to /__test__/s/:id.

Hook Body Effect Case
POST /release Releases a new app version for the sandbox; returns { version }. 45
POST /order-list { orders: [{ number, customer, total, date }] } Replaces the sandbox's orders (total in grosze). 47
POST /sms-clock { advanceMs } Moves the sandbox's server clock for texted codes forward. 51
POST /team-role { user, role } Sets a team member's role (viewer, editor or admin) on the server, as if someone else had changed it. 60
GET /otp { code }: the code most recently sent for the sandbox, or null. 63
POST /import-mode { manual: true | false } With manual: true, imports started afterwards do not advance on their own; import-step moves them. 67
POST /import-step { rows } Processes the next rows rows of the running import, sending their events. 67
POST /import-drop Closes every open event stream of the running import (the import itself goes on); returns { dropped }, how many were closed. 67
POST /upload-pace { bytesPerSecond } Limits how fast the server reads uploads; 0 removes the limit. 72
POST /price { price } Changes the product's price (grosze). 80
POST /goal { team: "home" | "away" } Scores a goal. 81
GET /score-reads How often the score was read. 81
POST /sale { endsInMs } Moves the end of the sale. 84
POST /price-list { sku, price } Changes one price (grosze). 90
GET /price-list-requests The price-list requests the server got, with the status it answered and the If-None-Match it received. 90
POST /notes-schema { version: 1 | 2 } Releases that version of the notes schema. 95
POST /gig-stock { left } Sets how many tickets are left. 104
POST /reader-expire Ends every reading-list session of the sandbox on the server. 110
POST /bus { departures: [{ line, to, time }] } Replaces the departures. 111
POST /bus-fail { times } The next times requests for departures fail. 111
POST /workspace { setupDone?, delayMs? } Whether setup is finished, and how long the settings take to load. 112
POST /saved-searches { names?, delayMs? } Sets the saved searches, and how long the list takes to load. 113
POST /claims-expire Ends every expense-claims session of the sandbox on the server. 119
POST /assistant-pace { ms } Time between words of an answer (120 ms by default, up to 2000). 124
POST /club-activity { events: [{ text, at }] } Replaces the events (at is an ISO date). 134
GET /notice-reads { reads }: how many times each notice was sent as read. 135
GET /cloudpix-exchanges { exchanges }: how many sign-in codes were traded. 136
GET /typing-signals { signals }: how many "I am typing" signals the server received. 137
POST /flight-pace { ms } How long the server waits before answering a search (up to 120000). 139
GET /flight-requests { started, completed, aborted } search requests. 139
POST /song-pace { ms: [n, ...] } Delays for successive saves, used in turn. 144
POST /song-fail { times } The next times saves fail. 144
GET /song-writes The saves in the order the server applied them. 144
POST /barber-clock { advanceMs } Moves the shop's clock forward. 148
POST /staff-pace { ms: [n, ...] } Delays for successive details requests, used in turn. 151
GET /staff-writes The saves the server received. 151
POST /trail-deploy Releases the next version of the trail map page for the sandbox (it starts at version 1). 158
POST /payslip { user: "alice" | "bob", month, net } Adds a payslip for that person. 161
POST /news-publish { count } Publishes count new stories at the top (1 to 100). 162
POST /team-chat { from, text, image?: { height } } Posts a message from someone else; the image height is in pixels. 168
POST /parts-limit { allowed, retryAfter, form: "seconds" | "date" } After allowed more searches, answers 429 with Retry-After as seconds or a date, retryAfter seconds long. 170
GET /parts-log { queries }: the search texts the server received, in order. 170
GET /csp-reports { reports }: the security policy violations the browser reported. 172
POST /video-upload-faults { faults: [{ part, after }] } Breaks that PATCH from then on: before the server keeps the part, or with after: true, after it and with a 500. 173
GET /video-upload-received { bytes }: how many bytes all PATCH requests carried. 173
POST /chat-history-fail { times } The next times loads of older messages fail. 174
GET /account-closed { closed }: whether the account has been closed. 175
POST /cafe-faults { badStock?, reorderFails? } The next badStock stock answers are unusable ({ items: null }); the next reorderFails reorders fail. 179
POST /printer-down { down } Takes the printer offline or back online. 180
GET /printer-checks { checks }: how many status checks the server received. 180
POST /team-expire-access Expires the current access token. 187
POST /team-end-session Ends the session on the server: every refresh token stops working. 187
GET /team-auth-stats { refreshes, ended }. 187
POST /region-pace { ms } The pause between the 16 parts of a download (40 ms by default). 188
POST /region-cut { region } Cuts the next download of that region (krakow, gdansk, tatry) off halfway. 188
GET /region-stats { completed, stopped } downloads. 188
POST /recipe-delay { ms } Slows every save down. 191
POST /recipe-fail-next The next save fails. 191
GET /weather-requests { count }: weather requests so far. 193
POST /weather-fail { on } Makes the weather service fail, or work again. 193
POST /room-fail { step: "book" | "invite" | "list" } The next request of that step fails. 194
GET /room-stats { bookAttempts, bookings, invites }. 194
POST /shopping-delay { ms } Slows every add down. 195
POST /shopping-fail-next The next add fails. 195

With TEST_HOOKS unset, every /__test__ path returns 404.