|
1 | 1 | import { module, test } from 'qunit';
|
2 | 2 | import { setupApplicationTest } from 'ember-qunit';
|
3 |
| -import { currentURL, findAll } from '@ember/test-helpers'; |
| 3 | +import { currentURL, findAll, click } from '@ember/test-helpers'; |
4 | 4 | import window, { setupWindowMock } from 'ember-window-mock';
|
| 5 | +import { Response } from 'ember-cli-mirage'; |
5 | 6 |
|
6 | 7 | import setupMirage from '../helpers/setup-mirage';
|
7 | 8 | import { visit } from '../helpers/visit-ignoring-abort';
|
@@ -62,4 +63,42 @@ module('Acceptance | api-tokens', function(hooks) {
|
62 | 63 | assert.dom('[data-test-error]', row2).doesNotExist();
|
63 | 64 | assert.dom('[data-test-token]', row2).doesNotExist();
|
64 | 65 | });
|
| 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 | + }); |
65 | 104 | });
|
0 commit comments