Commit
Cover the delete route in tests
commit
3783961
1 changed file with +18 and −1
modified server/routes/sessions.test.ts +18 −1
| @@ -40,7 +40,9 @@describe('session routes', () => { | ||
| 40 | 40 | .then((r) => r.json<Session>()) |
| 41 | 41 | |
| 42 | 42 | const list = await app.inject({ method: 'GET', url: '/api/sessions' }) |
| 43 | - expect(list.json()).toEqual([{ id: created.id, name: 'p', status: 'interviewing' }]) | |
| 43 | + expect(list.json()).toEqual([ | |
| 44 | + { id: created.id, name: 'p', status: 'interviewing', createdAt: created.createdAt }, | |
| 45 | + ]) | |
| 44 | 46 | |
| 45 | 47 | const fetched = await app.inject({ method: 'GET', url: `/api/sessions/${created.id}` }) |
| 46 | 48 | expect(fetched.json<Session>()).toEqual(created) |
| @@ -49,6 +51,21 @@describe('session routes', () => { | ||
| 49 | 51 | expect(missing.statusCode).toBe(404) |
| 50 | 52 | }) |
| 51 | 53 | |
| 54 | + it('deletes a session', async () => { | |
| 55 | + const created = await app | |
| 56 | + .inject({ method: 'POST', url: '/api/sessions', payload: { name: 'p', targetDir: '/tmp/p' } }) | |
| 57 | + .then((r) => r.json<Session>()) | |
| 58 | + | |
| 59 | + const deleted = await app.inject({ method: 'DELETE', url: `/api/sessions/${created.id}` }) | |
| 60 | + expect(deleted.statusCode).toBe(204) | |
| 61 | + | |
| 62 | + const fetched = await app.inject({ method: 'GET', url: `/api/sessions/${created.id}` }) | |
| 63 | + expect(fetched.statusCode).toBe(404) | |
| 64 | + | |
| 65 | + const again = await app.inject({ method: 'DELETE', url: `/api/sessions/${created.id}` }) | |
| 66 | + expect(again.statusCode).toBe(404) | |
| 67 | + }) | |
| 68 | + | |
| 52 | 69 | it('answering produces a user segment, an interviewer segment, and a coverage update', async () => { |
| 53 | 70 | const created = await app |
| 54 | 71 | .inject({ method: 'POST', url: '/api/sessions', payload: { name: 'p', targetDir: '/tmp/p' } }) |