The UI Said 'Saved.' Did the Audit Log Agree?
说明与用途
Cypress 测试脚本验证 UI、API 和审计事件,确保角色更改成功,使用有界轮询和关联 ID 避免竞争条件。
问题
A UI success toast does not guarantee that the backend persisted data, emitted audit events, or queued notifications.
结果
The recipe demonstrates how to assert UI feedback, API persistence, and audit events, avoiding race conditions with bounded polling and correlation IDs.
工作流
- Create a test user via HTTP POST
- Visit the admin user page
- Select a new role and click "Save changes"
- Assert the UI toast contains "Saved"
- Request the user API and assert the role is "editor"
- Poll the audit‑events endpoint for a "role.changed" event using bounded retries
- Assert the event contains the correct from/to values
证据
The green <strong>Saved</strong> toast answers one narrow question: did the React application render a success message?
For consequential workflows, test three postconditions: Browser – The user saw the expected state; API – The durable record contains the change; Side‑effect sink – The expected asynchronous event appeared
Use bounded polling: function waitForEvent(subjectId, action, attemptsLeft = 8, ... )
- 记录日期: 2026-10-10T16:40:58.429Z