Skip to content

Commit bb72655

Browse files
committed
Includes Ember tests for yanking
1 parent 321a4bb commit bb72655

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

app/components/yank-button.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
type="button"
44
local-class="button"
55
...attributes
6+
data-test-version-unyank-button={{@version.num}}
67
disabled={{@version.unyankTask.isRunning}}
78
{{on "click" (perform @version.unyankTask)}}
89
>
@@ -17,6 +18,7 @@
1718
type="button"
1819
local-class="button"
1920
...attributes
21+
data-test-version-yank-button={{@version.num}}
2022
disabled={{@version.yankTask.isRunning}}
2123
{{on "click" (perform @version.yankTask)}}
2224
>

app/models/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class Version extends Model {
7575
@(task(function* () {
7676
let response = yield fetch(`/api/v1/crates/${this.crate.id}/${this.num}/unyank`, { method: 'PUT' });
7777
if (!response.ok) {
78-
throw new Error(`Yank request for ${this.crateName} v${this.num} failed`);
78+
throw new Error(`Unyank request for ${this.crateName} v${this.num} failed`);
7979
}
8080
this.set('yanked', false);
8181

mirage/route-handlers/crates.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,28 @@ export function register(server) {
254254

255255
return {};
256256
});
257+
258+
server.delete('/api/v1/crates/:crate_id/:version/yank', (schema, request) => {
259+
const crateId = request.params.crate_id;
260+
const versionNum = request.params.version;
261+
262+
const version = schema.versions.findBy({ crateId, num: versionNum });
263+
if (!version) {
264+
return notFound();
265+
}
266+
267+
return {};
268+
});
269+
270+
server.put('/api/v1/crates/:crate_id/:version/unyank', (schema, request) => {
271+
const crateId = request.params.crate_id;
272+
const versionNum = request.params.version;
273+
274+
const version = schema.versions.findBy({ crateId, num: versionNum });
275+
if (!version) {
276+
return notFound();
277+
}
278+
279+
return {};
280+
});
257281
}

tests/acceptance/crate-test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, fillIn, currentURL, currentRouteName, visit } from '@ember/test-helpers';
1+
import { click, fillIn, currentURL, currentRouteName, visit, waitFor } from '@ember/test-helpers';
22
import { setupApplicationTest } from 'ember-qunit';
33
import { module, test } from 'qunit';
44

@@ -219,6 +219,25 @@ module('Acceptance | crate page', function (hooks) {
219219
assert.dom('[data-test-license]').hasText('MIT/Apache-2.0');
220220
});
221221

222+
test('crates can be yanked by owner', async function (assert) {
223+
this.server.loadFixtures();
224+
225+
let user = this.server.schema.users.findBy({ login: 'thehydroimpulse' });
226+
this.authenticateAs(user);
227+
228+
await visit('/crates/nanomsg');
229+
await click('[data-test-version-yank-button="0.5.0"]');
230+
assert.dom('[data-test-version-yank-button="0.5.0"]').hasText('Yanking...');
231+
assert.dom('[data-test-version-yank-button="0.5.0"]').isDisabled();
232+
233+
await waitFor('[data-test-version-unyank-button="0.5.0"]');
234+
await click('[data-test-version-unyank-button="0.5.0"]');
235+
assert.dom('[data-test-version-unyank-button="0.5.0"]').hasText('Unyanking...');
236+
assert.dom('[data-test-version-unyank-button="0.5.0"]').isDisabled();
237+
238+
await waitFor('[data-test-version-yank-button="0.5.0"]');
239+
});
240+
222241
test('navigating to the owners page when not logged in', async function (assert) {
223242
this.server.loadFixtures();
224243

0 commit comments

Comments
 (0)