|
| 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 | DELETE /api/v1/crates/:name', function (hooks) { |
| 9 | + setupTest(hooks); |
| 10 | + setupMirage(hooks); |
| 11 | + |
| 12 | + test('returns 403 if unauthenticated', async function (assert) { |
| 13 | + let response = await fetch('/api/v1/crates/foo', { method: 'DELETE' }); |
| 14 | + assert.strictEqual(response.status, 403); |
| 15 | + assert.deepEqual(await response.json(), { |
| 16 | + errors: [{ detail: 'must be logged in to perform that action' }], |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + test('returns 404 for unknown crates', async function (assert) { |
| 21 | + let user = this.server.create('user'); |
| 22 | + this.authenticateAs(user); |
| 23 | + |
| 24 | + let response = await fetch('/api/v1/crates/foo', { method: 'DELETE' }); |
| 25 | + assert.strictEqual(response.status, 404); |
| 26 | + assert.deepEqual(await response.json(), { errors: [{ detail: 'crate `foo` does not exist' }] }); |
| 27 | + }); |
| 28 | + |
| 29 | + test('deletes crates', async function (assert) { |
| 30 | + let user = this.server.create('user'); |
| 31 | + this.authenticateAs(user); |
| 32 | + |
| 33 | + let crate = this.server.create('crate', { name: 'foo' }); |
| 34 | + this.server.create('crate-ownership', { crate, user }); |
| 35 | + |
| 36 | + let response = await fetch('/api/v1/crates/foo', { method: 'DELETE' }); |
| 37 | + assert.strictEqual(response.status, 204); |
| 38 | + assert.deepEqual(await response.text(), ''); |
| 39 | + |
| 40 | + assert.strictEqual(this.server.schema.crates.findBy({ name: 'foo' }), null); |
| 41 | + }); |
| 42 | +}); |
0 commit comments