Files
threshold-ui/ui/admin/tests/unit/controllers/account/change-password-test.js
T
Lisbet Alvarez 72f7c8a92d fix: 🐛 OIDC authentications not properly showing username (#2930)
* fix: 🐛 properly show username for oidc auth method in user menu

* test: 💍 fix admin ui tests

* test: 💍 fix desktop ui tests

* refactor: 💡 admin to not store username in authenticated object

* refactor: 💡 use getter in app controller

* test: 💍 POC for how we could update our tests to use auth account

* refactor: 💡 remove unused service

* test: 💍 fix all tests in ui/admin

* test: 💍 revert one change

* refactor: 💡 update ui/desktop w/ feedback + fix tests

* refactor: 💡 add in error handling

* refactor: 💡 cleanup unused service

* test: 💍 fix e2e test selector

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
2025-10-30 12:49:30 -07:00

78 lines
2.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupSqlite } from 'api/test-support/helpers/sqlite';
import { authenticateSession } from 'ember-simple-auth/test-support';
module('Unit | Controller | account/change-password', function (hooks) {
setupTest(hooks);
// `setupSqlite` had to be moved before `setupMirage` or else the db object would
// be destroyed before route query requests had a chance to run.
setupSqlite(hooks);
setupMirage(hooks);
let controller;
let store;
const instances = {
scopes: {
global: null,
},
authMethod: null,
account: null,
};
const urls = {
globalScope: null,
};
hooks.beforeEach(async function () {
instances.scopes.global = this.server.create(
'scope',
{ id: 'global' },
'withGlobalAuth',
);
instances.authMethod = this.server.schema.authMethods.first();
instances.account = this.server.schema.accounts.first();
await authenticateSession({
isGlobal: true,
account_id: instances.account.id,
});
controller = this.owner.lookup('controller:account/change-password');
store = this.owner.lookup('service:store');
urls.globalScope = `/scopes/global`;
});
test('it exists', function (assert) {
assert.ok(controller);
});
test('changePassword action makes the correct API call with correct values', async function (assert) {
assert.expect(2);
const password = 'current password';
const newPassword = 'new password';
this.server.post(
'/accounts/:idMethod',
(_, { params: { idMethod }, requestBody }) => {
const attrs = JSON.parse(requestBody);
assert.strictEqual(attrs.current_password, password);
assert.strictEqual(attrs.new_password, newPassword);
const id = idMethod.split(':')[0];
return { id };
},
);
await visit(urls.globalScope);
const account = await store.findRecord('account', instances.account.id);
await controller.changePassword(account, password, newPassword);
});
});