Repository: hashicorp/vault
File: ui/tests/acceptance/config-ui/login-settings-test.js (JavaScript)

Code before:
 * SPDX-License-Identifier: BUSL-1.1
 */

import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { click, visit, currentRouteName } from '@ember/test-helpers';
import { login } from 'vault/tests/helpers/auth/auth-helpers';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { runCmd } from 'vault/tests/helpers/commands';

module('Acceptance | Enterprise | config-ui/login-settings', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  hooks.beforeEach(async function () {
    const version = this.owner.lookup('service:version');
    version.type = 'enterprise';
    await login();
  });

  test('fetched login rule list renders', async function (assert) {
    await runCmd([
      'write sys/config/ui/login/default-auth/testRule backupAuthTypes=[] defaultAuthType=okta disableInheritance=false namespace=ns1',
      'write sys/config/ui/login/default-auth/testRule2 backupAuthTypes=[] defaultAuthType=ldap disableInheritance=false namespace=ns2',
    ]);

    // Visit the login settings list index page
    await visit('vault/config-ui/login-settings');

    // verify fetched rules are rendered in list
    assert.dom('.linked-block-item').exists({ count: 2 });
  });

  test('delete rule from list view', async function (assert) {
    // Visit the login settings list index page
    await visit('vault/config-ui/login-settings');

    await click(GENERAL.menuTrigger);
    await click(GENERAL.menuItem('delete-rule'));

    assert.dom(GENERAL.confirmationModal).exists();
    await click(GENERAL.confirmButton);

    // verify success message from deletion
    assert.dom(GENERAL.latestFlashContent).includesText('Successfully deleted rule testRule.');
  });

  test('navigate to rule details page and renders rule data', async function (assert) {
    // visit individual rule page
    await visit('vault/config-ui/login-settings');

Review comment (suggestion):
i'm kind of surprised these are camel cased and not snake cased 🤔 i thought the api service was transforming them (when we were testing last week). Since this is mimicking CLI commands I'm pretty sure these should follow the API write syntax which is snake cased, unless the web console does something strange

Code after:
 * SPDX-License-Identifier: BUSL-1.1
 */

import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { click, visit, currentRouteName } from '@ember/test-helpers';
import { login } from 'vault/tests/helpers/auth/auth-helpers';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { runCmd } from 'vault/tests/helpers/commands';

module('Acceptance | Enterprise | config-ui/login-settings', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  hooks.beforeEach(async function () {
    await login();

    // create login rules
    await runCmd([
      'write sys/config/ui/login/default-auth/testRule backup_auth_types=[] default_auth_type=okta disable_inheritance=false namespace=ns1',
      'write sys/config/ui/login/default-auth/testRule2 backup_auth_types=[] default_auth_type=ldap disable_inheritance=true namespace=ns2',
    ]);
  });

  hooks.afterEach(async function () {
    // cleanup login rules
    await runCmd([
      'delete sys/config/ui/login/default-auth/testRule',
      'delete sys/config/ui/login/default-auth/testRule2',
    ]);
  });

  test('fetched login rule list renders', async function (assert) {
    // Visit the login settings list index page
    await visit('vault/config-ui/login-settings');

    // verify fetched rules are rendered in list
    assert.dom('.linked-block-item').exists({ count: 2 });
  });

  test('delete rule from list view', async function (assert) {
    // Visit the login settings list index page
    await visit('vault/config-ui/login-settings');

    await click(GENERAL.menuTrigger);
    await click(GENERAL.menuItem('delete-rule'));

    assert.dom(GENERAL.confirmationModal).exists();
    await click(GENERAL.confirmButton);