|
| 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 | +const YANK_BODY = JSON.stringify({ |
| 9 | + version: { |
| 10 | + yanked: true, |
| 11 | + yank_message: 'some reason', |
| 12 | + }, |
| 13 | +}); |
| 14 | + |
| 15 | +module('Mirage | PATCH /api/v1/crates/:crate/:version', function (hooks) { |
| 16 | + setupTest(hooks); |
| 17 | + setupMirage(hooks); |
| 18 | + |
| 19 | + test('returns 403 if unauthenticated', async function (assert) { |
| 20 | + let response = await fetch('/api/v1/crates/foo/1.0.0', { method: 'PATCH', body: YANK_BODY }); |
| 21 | + assert.strictEqual(response.status, 403); |
| 22 | + assert.deepEqual(await response.json(), { |
| 23 | + errors: [{ detail: 'must be logged in to perform that action' }], |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + test('returns 404 for unknown crates', async function (assert) { |
| 28 | + let user = this.server.create('user'); |
| 29 | + this.authenticateAs(user); |
| 30 | + |
| 31 | + let response = await fetch('/api/v1/crates/foo/1.0.0', { method: 'PATCH', body: YANK_BODY }); |
| 32 | + assert.strictEqual(response.status, 404); |
| 33 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] }); |
| 34 | + }); |
| 35 | + |
| 36 | + test('returns 404 for unknown versions', async function (assert) { |
| 37 | + this.server.create('crate', { name: 'foo' }); |
| 38 | + |
| 39 | + let user = this.server.create('user'); |
| 40 | + this.authenticateAs(user); |
| 41 | + |
| 42 | + let response = await fetch('/api/v1/crates/foo/1.0.0', { method: 'PATCH', body: YANK_BODY }); |
| 43 | + assert.strictEqual(response.status, 404); |
| 44 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] }); |
| 45 | + }); |
| 46 | + |
| 47 | + test('yanks the version', async function (assert) { |
| 48 | + let crate = this.server.create('crate', { name: 'foo' }); |
| 49 | + let version = this.server.create('version', { crate, num: '1.0.0', yanked: false }); |
| 50 | + assert.false(version.yanked); |
| 51 | + assert.strictEqual(version.yank_message, null); |
| 52 | + |
| 53 | + let user = this.server.create('user'); |
| 54 | + this.authenticateAs(user); |
| 55 | + |
| 56 | + let response = await fetch('/api/v1/crates/foo/1.0.0', { method: 'PATCH', body: YANK_BODY }); |
| 57 | + assert.strictEqual(response.status, 200); |
| 58 | + assert.deepEqual(await response.json(), { |
| 59 | + version: { |
| 60 | + crate: 'foo', |
| 61 | + crate_size: 0, |
| 62 | + created_at: '2010-06-16T21:30:45Z', |
| 63 | + dl_path: '/api/v1/crates/foo/1.0.0/download', |
| 64 | + downloads: 0, |
| 65 | + id: '1', |
| 66 | + license: 'MIT/Apache-2.0', |
| 67 | + links: { |
| 68 | + dependencies: '/api/v1/crates/foo/1.0.0/dependencies', |
| 69 | + version_downloads: '/api/v1/crates/foo/1.0.0/downloads', |
| 70 | + }, |
| 71 | + num: '1.0.0', |
| 72 | + published_by: null, |
| 73 | + readme_path: '/api/v1/crates/foo/1.0.0/readme', |
| 74 | + rust_version: null, |
| 75 | + updated_at: '2017-02-24T12:34:56Z', |
| 76 | + yank_message: 'some reason', |
| 77 | + yanked: true, |
| 78 | + }, |
| 79 | + }); |
| 80 | + |
| 81 | + user.reload(); |
| 82 | + assert.true(version.yanked); |
| 83 | + assert.strictEqual(version.yank_message, 'some reason'); |
| 84 | + }); |
| 85 | +}); |
0 commit comments