Skip to content

Commit 3e035b0

Browse files
committed
tests/api-token: Add tests for token revocation
1 parent 4db1e60 commit 3e035b0

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/acceptance/api-token-test.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { module, test } from 'qunit';
22
import { setupApplicationTest } from 'ember-qunit';
3-
import { currentURL, findAll } from '@ember/test-helpers';
3+
import { currentURL, findAll, click } from '@ember/test-helpers';
44
import window, { setupWindowMock } from 'ember-window-mock';
5+
import { Response } from 'ember-cli-mirage';
56

67
import setupMirage from '../helpers/setup-mirage';
78
import { visit } from '../helpers/visit-ignoring-abort';
@@ -62,4 +63,42 @@ module('Acceptance | api-tokens', function(hooks) {
6263
assert.dom('[data-test-error]', row2).doesNotExist();
6364
assert.dom('[data-test-token]', row2).doesNotExist();
6465
});
66+
67+
test('API tokens can be revoked', async function(assert) {
68+
prepare(this);
69+
70+
this.server.delete('/api/v1/me/tokens/:id', function(schema, request) {
71+
assert.step(`delete id:${request.params.id}`);
72+
return {};
73+
});
74+
75+
await visit('/me');
76+
assert.equal(currentURL(), '/me');
77+
assert.dom('[data-test-api-token]').exists({ count: 2 });
78+
79+
await click('[data-test-api-token="1"] [data-test-revoke-token-button]');
80+
assert.verifySteps(['delete id:1']);
81+
82+
assert.dom('[data-test-api-token]').exists({ count: 1 });
83+
assert.dom('[data-test-api-token="2"]').exists();
84+
assert.dom('[data-test-error]').doesNotExist();
85+
});
86+
87+
test('failed API tokens revocation shows an error', async function(assert) {
88+
prepare(this);
89+
90+
this.server.delete('/api/v1/me/tokens/:id', function() {
91+
return new Response(500, {}, {});
92+
});
93+
94+
await visit('/me');
95+
assert.equal(currentURL(), '/me');
96+
assert.dom('[data-test-api-token]').exists({ count: 2 });
97+
98+
await click('[data-test-api-token="1"] [data-test-revoke-token-button]');
99+
assert.dom('[data-test-api-token]').exists({ count: 2 });
100+
assert.dom('[data-test-api-token="2"]').exists();
101+
assert.dom('[data-test-api-token="1"]').exists();
102+
assert.dom('[data-test-error]').includesText('An error occurred while revoking this token');
103+
});
65104
});

0 commit comments

Comments
 (0)