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