|
| 1 | +import { assert, test } from 'vitest'; |
| 2 | + |
| 3 | +import { db } from '../../index.js'; |
| 4 | + |
| 5 | +test('returns 404 for unknown crates', async function () { |
| 6 | + let response = await fetch('/api/v1/crates/foo/1.0.0-beta.1'); |
| 7 | + assert.strictEqual(response.status, 404); |
| 8 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] }); |
| 9 | +}); |
| 10 | + |
| 11 | +test('returns 404 for unknown versions', async function () { |
| 12 | + let crate = db.crate.create({ name: 'rand' }); |
| 13 | + db.version.create({ crate, num: '1.0.0-alpha.1' }); |
| 14 | + let response = await fetch('/api/v1/crates/rand/1.0.0-beta.1'); |
| 15 | + assert.strictEqual(response.status, 404); |
| 16 | + assert.deepEqual(await response.json(), { |
| 17 | + errors: [{ detail: 'crate `rand` does not have a version `1.0.0-beta.1`' }], |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +test('returns a version object for known version', async function () { |
| 22 | + let crate = db.crate.create({ name: 'rand' }); |
| 23 | + db.version.create({ crate, num: '1.0.0-beta.1' }); |
| 24 | + |
| 25 | + let response = await fetch('/api/v1/crates/rand/1.0.0-beta.1'); |
| 26 | + assert.strictEqual(response.status, 200); |
| 27 | + assert.deepEqual(await response.json(), { |
| 28 | + version: { |
| 29 | + crate: 'rand', |
| 30 | + crate_size: 162_963, |
| 31 | + created_at: '2010-06-16T21:30:45Z', |
| 32 | + dl_path: '/api/v1/crates/rand/1.0.0-beta.1/download', |
| 33 | + downloads: 3702, |
| 34 | + features: {}, |
| 35 | + id: 1, |
| 36 | + license: 'MIT', |
| 37 | + links: { |
| 38 | + dependencies: '/api/v1/crates/rand/1.0.0-beta.1/dependencies', |
| 39 | + version_downloads: '/api/v1/crates/rand/1.0.0-beta.1/downloads', |
| 40 | + }, |
| 41 | + num: '1.0.0-beta.1', |
| 42 | + published_by: null, |
| 43 | + readme_path: '/api/v1/crates/rand/1.0.0-beta.1/readme', |
| 44 | + rust_version: null, |
| 45 | + updated_at: '2017-02-24T12:34:56Z', |
| 46 | + yank_message: null, |
| 47 | + yanked: false, |
| 48 | + }, |
| 49 | + }); |
| 50 | +}); |
0 commit comments