add test coverage (#19226)

This commit is contained in:
Angel Garbarino 2023-02-16 12:28:19 -07:00 committed by GitHub
parent 18043a05e8
commit c48d36eb8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { capabilitiesStub } from 'vault/tests/helpers/stubs';
module('Integration | Component | database-role-edit', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.store.pushPayload('database-role', {
modelName: 'database/role',
database: ['my-mongodb-database'],
backend: 'database',
type: 'static',
name: 'my-static-role',
id: 'my-static-role',
});
this.store.pushPayload('database-role', {
modelName: 'database/role',
database: ['my-mongodb-database'],
backend: 'database',
type: 'dynamic',
name: 'my-dynamic-role',
id: 'my-dynamic-role',
});
this.modelStatic = this.store.peekRecord('database/role', 'my-static-role');
this.modelDynamic = this.store.peekRecord('database/role', 'my-dynamic-role');
});
test('it should show Get credentials button when a user has the correct policy', async function (assert) {
this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['read']));
await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
assert.dom('[data-test-database-role-creds="static"]').exists('Get credentials button exists');
});
test('it should show Generate credentials button when a user has the correct policy', async function (assert) {
this.server.post('/sys/capabilities-self', capabilitiesStub('database/creds/my-role', ['read']));
await render(hbs`<DatabaseRoleEdit @model={{this.modelDynamic}} @mode="show"/>`);
assert.dom('[data-test-database-role-creds="dynamic"]').exists('Generate credentials button exists');
});
});