|
| 1 | +import { assert, test } from 'vitest'; |
| 2 | + |
| 3 | +import { db } from '../../index.js'; |
| 4 | + |
| 5 | +test('returns 403 if unauthenticated', async function () { |
| 6 | + let response = await fetch('/api/v1/crates/foo/1.0.0/rebuild_docs', { method: 'POST' }); |
| 7 | + assert.strictEqual(response.status, 403); |
| 8 | + assert.deepEqual(await response.json(), { |
| 9 | + errors: [{ detail: 'must be logged in to perform that action' }], |
| 10 | + }); |
| 11 | +}); |
| 12 | + |
| 13 | +test('returns 404 for unknown crates', async function () { |
| 14 | + let user = db.user.create(); |
| 15 | + db.mswSession.create({ user }); |
| 16 | + |
| 17 | + let response = await fetch('/api/v1/crates/foo/1.0.0/rebuild_docs', { method: 'POST' }); |
| 18 | + assert.strictEqual(response.status, 404); |
| 19 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] }); |
| 20 | +}); |
| 21 | + |
| 22 | +test('returns 404 for unknown versions', async function () { |
| 23 | + db.crate.create({ name: 'foo' }); |
| 24 | + |
| 25 | + let user = db.user.create(); |
| 26 | + db.mswSession.create({ user }); |
| 27 | + |
| 28 | + let response = await fetch('/api/v1/crates/foo/1.0.0/rebuild_docs', { method: 'POST' }); |
| 29 | + assert.strictEqual(response.status, 404); |
| 30 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] }); |
| 31 | +}); |
| 32 | + |
| 33 | +test('triggers a rebuild for the crate documentation', async function () { |
| 34 | + let crate = db.crate.create({ name: 'foo' }); |
| 35 | + db.version.create({ crate, num: '1.0.0' }); |
| 36 | + |
| 37 | + let user = db.user.create(); |
| 38 | + db.mswSession.create({ user }); |
| 39 | + |
| 40 | + let response = await fetch('/api/v1/crates/foo/1.0.0/rebuild_docs', { method: 'POST' }); |
| 41 | + assert.strictEqual(response.status, 201); |
| 42 | + assert.deepEqual(await response.json(), null); |
| 43 | +}); |
0 commit comments