From c933aa88403362e986729fd1b7f1e5aa449011e9 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Wed, 14 Dec 2022 13:36:30 -0600 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20delete=20tests=20f?= =?UTF-8?q?or=20JSON=20Credentials=20(#1526)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: 💍 Add delete tests for JSON Credentials ✅ Closes: ICU-6806 * refactor: 💡 update JSON variable names --- .../credentials/delete-test.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/ui/admin/tests/acceptance/credential-store/credentials/delete-test.js b/ui/admin/tests/acceptance/credential-store/credentials/delete-test.js index 57192d5f0..c5474d917 100644 --- a/ui/admin/tests/acceptance/credential-store/credentials/delete-test.js +++ b/ui/admin/tests/acceptance/credential-store/credentials/delete-test.js @@ -13,6 +13,7 @@ module( let getUsernamePasswordCredentialCount; let getUsernameKeyPairCredentialCount; + let getJSONCredentialCount; const instances = { scopes: { @@ -28,6 +29,7 @@ module( credentials: null, usernamePasswordCredential: null, usernameKeyPairCredential: null, + jsonCredential: null, }; hooks.beforeEach(function () { @@ -54,6 +56,11 @@ module( credentialStore: instances.staticCredentialStore, type: 'ssh_private_key', }); + instances.jsonCredential = this.server.create('credential', { + scope: instances.scopes.project, + credentialStore: instances.staticCredentialStore, + type: 'json', + }); // Generate route URLs for resources urls.projectScope = `/scopes/${instances.scopes.project.id}`; urls.credentialStores = `${urls.projectScope}/credential-stores`; @@ -61,6 +68,7 @@ module( urls.credentials = `${urls.staticCredentialStore}/credentials`; urls.usernamePasswordCredential = `${urls.credentials}/${instances.usernamePasswordCredential.id}`; urls.usernameKeyPairCredential = `${urls.credentials}/${instances.usernameKeyPairCredential.id}`; + urls.jsonCredential = `${urls.credentials}/${instances.jsonCredential.id}`; // Generate resource counter getUsernamePasswordCredentialCount = () => { return this.server.schema.credentials.where({ @@ -71,6 +79,10 @@ module( return this.server.schema.credentials.where({ type: 'ssh_private_key' }) .length; }; + getJSONCredentialCount = () => { + return this.server.schema.credentials.where({ type: 'json' }) + .length; + }; authenticateSession({}); }); @@ -100,6 +112,19 @@ module( ); }); + test('can delete JSON credential', async function (assert) { + assert.expect(2); + const jsonCredentialCount = + getJSONCredentialCount(); + await visit(urls.jsonCredential); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.strictEqual(currentURL(), urls.credentials); + assert.strictEqual( + getJSONCredentialCount(), + jsonCredentialCount - 1 + ); + }); + test('cannot delete a username & password credential without proper authorization', async function (assert) { assert.expect(3); const usernamePasswordCredentialCount = @@ -138,6 +163,25 @@ module( ); }); + test('cannot delete a JSON credential without proper authorization', async function (assert) { + assert.expect(3); + const jsonCredentialCount = + getJSONCredentialCount(); + instances.jsonCredential.authorized_actions = + instances.jsonCredential.authorized_actions.filter( + (item) => item !== 'delete' + ); + await visit(urls.jsonCredential); + assert.strictEqual(currentURL(), urls.jsonCredential); + assert + .dom('.rose-layout-page-actions .rose-dropdown-button-danger') + .doesNotExist(); + assert.strictEqual( + getJSONCredentialCount(), + jsonCredentialCount + ); + }); + test('can accept delete username & password credential via dialog', async function (assert) { assert.expect(2); const confirmService = this.owner.lookup('service:confirm'); @@ -170,6 +214,22 @@ module( ); }); + test('can accept delete JSON credential via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + const jsonCredentialCount = + getJSONCredentialCount(); + await visit(urls.jsonCredential); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await click('.rose-dialog footer .rose-button-primary'); + assert.strictEqual(currentURL(), urls.credentials); + assert.strictEqual( + getJSONCredentialCount(), + jsonCredentialCount - 1 + ); + }); + test('can cancel delete username & password credential via dialog', async function (assert) { assert.expect(2); const confirmService = this.owner.lookup('service:confirm'); @@ -202,6 +262,22 @@ module( ); }); + test('can cancel delete JSON credential via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + const jsonCredentialCount = + getJSONCredentialCount(); + await visit(urls.jsonCredential); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await click('.rose-dialog footer .rose-button-secondary'); + assert.strictEqual(currentURL(), urls.jsonCredential); + assert.strictEqual( + getJSONCredentialCount(), + jsonCredentialCount + ); + }); + test('deleting a username & password credential which errors displays error message', async function (assert) { assert.expect(1); this.server.del('/credentials/:id', () => { @@ -237,5 +313,23 @@ module( await click('.rose-layout-page-actions .rose-dropdown-button-danger'); assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); }); + + test('deleting a JSON credential which errors displays error message', async function (assert) { + assert.expect(1); + this.server.del('/credentials/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.jsonCredential); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + }); } );