Write MSW handlers for transfer lifecycle states
Testing + Tooling Drills · API + Mock Boundaries
Mock success, slow pending, backend empty while local pending exists, retryable error, and reconciliation completion.
Prompt
Write MSW handlers for transfer lifecycle states
This is a hands-on rep. Attempt the drill before reading the model answer, then narrate the tradeoffs as if an interviewer is watching.
The mock scenarios should map directly to user-visible states.
What to ground before answering
Mock success, slow pending, backend empty while local pending exists, retryable error, and reconciliation completion.
Focus vocabulary: MSW, testing, fixtures.
The useful mental model is not to memorize a perfect answer. It is to explain what owns the data, what can fail, what the user sees, and what test would prove the behavior.
Map transfer scenarios to mock responses
Make the behavior executable before comparing against the model answer.
type Scenario = 'success' | 'slow-pending' | 'backend-empty' | 'retryable-error' | 'reconciled';
type MockResponse = { status: number; body: { state: string; retryAfterMs?: number } };
function transferMockResponse(scenario: Scenario): MockResponse {
// TODO: return the HTTP status and body a UI test should see.
return { status: 200, body: { state: 'unknown' } };
}Interview explanation prompt
- What problem is this practice item really testing?
- What state or contract boundary must be explicit?
- What edge case would cause a production regression?
- What would you test first?
- How would you explain the tradeoff in two minutes?
Self-grade
- Strong answer handles the edge cases before polishing syntax.
- Strong answer explains why the chosen type or function boundary prevents bugs.
- Weak answer passes only the happy path or hides uncertainty in booleans and nullable fields.
Model Answer
function transferMockResponse(scenario: Scenario): MockResponse {
switch (scenario) {
case 'success':
return { status: 202, body: { state: 'submitted' } };
case 'slow-pending':
return { status: 200, body: { state: 'pending', retryAfterMs: 1000 } };
case 'backend-empty':
return { status: 404, body: { state: 'not-indexed-yet', retryAfterMs: 1000 } };
case 'retryable-error':
return { status: 503, body: { state: 'retryable-error', retryAfterMs: 2000 } };
case 'reconciled':
return { status: 200, body: { state: 'reconciled' } };
}
}Recall before moving on
- What is the one-sentence answer for "Write MSW handlers for transfer lifecycle states"?
- Which real experience from PR TIMES, React/TypeScript migration, or systems work supports it?
- What edge case would you volunteer before the interviewer asks?
- What is the smallest test or artifact that proves the design works?