Refactor type to use const values (#1695)

* refactor: 💡 use auth-method type consts
This commit is contained in:
lisbet-alvarez authored and GitHub committed 2023-05-23 12:37:35 -07:00
1 parent 8d77bc60b3
commit fde4ec4e05
13 files changed
+55 -27

No files matched your search

+2 -1
View File
@@ -7,6 +7,7 @@ import GeneratedRoleModel from '../generated/models/role';
import { attr } from '@ember-data/model'; import { attr } from '@ember-data/model';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { all, resolve } from 'rsvp'; import { all, resolve } from 'rsvp';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
export default class RoleModel extends GeneratedRoleModel { export default class RoleModel extends GeneratedRoleModel {
// =services // =services
@@ -133,7 +134,7 @@ export default class RoleModel extends GeneratedRoleModel {
// Collect all auth methods. // Collect all auth methods.
const authMethods = this.resourceFilterStore.queryBy( const authMethods = this.resourceFilterStore.queryBy(
'auth-method', 'auth-method',
{ type: 'oidc' }, { type: TYPE_AUTH_METHOD_OIDC },
{ scope_id: 'global', recursive: true } { scope_id: 'global', recursive: true }
); );
@@ -5,12 +5,13 @@
import { Factory } from 'miragejs'; import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker'; import { faker } from '@faker-js/faker';
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
/** /**
* GeneratedAccountFactory * GeneratedAccountFactory
*/ */
export default Factory.extend({ export default Factory.extend({
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
created_time: () => faker.date.recent(), created_time: () => faker.date.recent(),
updated_time: () => faker.date.recent(), updated_time: () => faker.date.recent(),
version: () => faker.datatype.number(), version: () => faker.datatype.number(),
+1 -1
View File
@@ -30,7 +30,7 @@ module('Unit | Model | account', function (hooks) {
assert.expect(2); assert.expect(2);
store = this.owner.lookup('service:store'); store = this.owner.lookup('service:store');
let model = store.createRecord('account', { let model = store.createRecord('account', {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
}); });
assert.notOk(model.accountName); assert.notOk(model.accountName);
model.login_name = 'foobar'; model.login_name = 'foobar';
@@ -5,6 +5,10 @@
import { module, test } from 'qunit'; import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit'; import { setupTest } from 'ember-qunit';
import {
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
} from 'api/models/auth-method';
module('Unit | Serializer | account', function (hooks) { module('Unit | Serializer | account', function (hooks) {
setupTest(hooks); setupTest(hooks);
@@ -14,7 +18,7 @@ module('Unit | Serializer | account', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account'); const serializer = store.serializerFor('account');
const record = store.createRecord('account', { const record = store.createRecord('account', {
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -27,7 +31,7 @@ module('Unit | Serializer | account', function (hooks) {
const snapshot = record._createSnapshot(); const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot); const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, { assert.deepEqual(serializedRecord, {
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -48,7 +52,7 @@ module('Unit | Serializer | account', function (hooks) {
id: '1', id: '1',
type: 'account', type: 'account',
attributes: { attributes: {
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -65,7 +69,7 @@ module('Unit | Serializer | account', function (hooks) {
const serializedRecord = serializer.serialize(snapshot); const serializedRecord = serializer.serialize(snapshot);
assert.notOk(serializedRecord.attributes); assert.notOk(serializedRecord.attributes);
assert.deepEqual(serializedRecord, { assert.deepEqual(serializedRecord, {
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -78,7 +82,7 @@ module('Unit | Serializer | account', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account'); const serializer = store.serializerFor('account');
const record = store.createRecord('account', { const record = store.createRecord('account', {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -88,7 +92,7 @@ module('Unit | Serializer | account', function (hooks) {
const snapshot = record._createSnapshot(); const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot); const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, { assert.deepEqual(serializedRecord, {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -104,7 +108,7 @@ module('Unit | Serializer | account', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account'); const serializer = store.serializerFor('account');
const record = store.createRecord('account', { const record = store.createRecord('account', {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -117,7 +121,7 @@ module('Unit | Serializer | account', function (hooks) {
}; };
const serializedRecord = serializer.serialize(snapshot); const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, { assert.deepEqual(serializedRecord, {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
auth_method_id: '1', auth_method_id: '1',
description: 'Description', description: 'Description',
@@ -138,7 +142,7 @@ module('Unit | Serializer | account', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account'); const serializer = store.serializerFor('account');
const record = store.createRecord('account', { const record = store.createRecord('account', {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
description: 'Description', description: 'Description',
login_name: 'Login Name', login_name: 'Login Name',
@@ -162,7 +166,7 @@ module('Unit | Serializer | account', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account'); const serializer = store.serializerFor('account');
const record = store.createRecord('account', { const record = store.createRecord('account', {
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
name: 'Name', name: 'Name',
description: 'Description', description: 'Description',
login_name: 'Login Name', login_name: 'Login Name',
@@ -8,6 +8,11 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers'; import { render, find } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars'; import { hbs } from 'ember-cli-htmlbars';
import { setupIntl } from 'ember-intl/test-support'; import { setupIntl } from 'ember-intl/test-support';
import {
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
} from 'api/models/auth-method';
module('Integration | Component | form | authenticate', function (hooks) { module('Integration | Component | form | authenticate', function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
@@ -18,7 +23,9 @@ module('Integration | Component | form | authenticate', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
this.model = store.createRecord('auth-method', { type: 'ldap' }); this.model = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_LDAP,
});
this.submit = () => {}; this.submit = () => {};
this.disabled = () => {}; this.disabled = () => {};
@@ -39,7 +46,9 @@ module('Integration | Component | form | authenticate', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
this.model = store.createRecord('auth-method', { type: 'password' }); this.model = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_PASSWORD,
});
this.submit = () => {}; this.submit = () => {};
this.disabled = () => {}; this.disabled = () => {};
@@ -60,7 +69,9 @@ module('Integration | Component | form | authenticate', function (hooks) {
const store = this.owner.lookup('service:store'); const store = this.owner.lookup('service:store');
this.model = store.createRecord('auth-method', { type: 'oidc' }); this.model = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_OIDC,
});
this.submit = () => {}; this.submit = () => {};
this.disabled = () => {}; this.disabled = () => {};
@@ -10,6 +10,7 @@ import { hash, all } from 'rsvp';
import { loading } from 'ember-loading'; import { loading } from 'ember-loading';
import { notifySuccess, notifyError } from 'core/decorators/notify'; import { notifySuccess, notifyError } from 'core/decorators/notify';
import { resourceFilter } from 'core/decorators/resource-filter'; import { resourceFilter } from 'core/decorators/resource-filter';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route { export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
// =services // =services
@@ -75,12 +76,12 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
const oidcAuthMethods = scopeIDs?.length const oidcAuthMethods = scopeIDs?.length
? await this.resourceFilterStore.queryBy( ? await this.resourceFilterStore.queryBy(
'auth-method', 'auth-method',
{ scope_id: scopeIDs, type: 'oidc' }, { scope_id: scopeIDs, type: TYPE_AUTH_METHOD_OIDC },
{ scope_id: 'global', recursive: true } { scope_id: 'global', recursive: true }
) )
: await this.resourceFilterStore.queryBy( : await this.resourceFilterStore.queryBy(
'auth-method', 'auth-method',
{ type: 'oidc' }, { type: TYPE_AUTH_METHOD_OIDC },
{ scope_id: 'global', recursive: true } { scope_id: 'global', recursive: true }
); );
//extract oidc authMethod IDs //extract oidc authMethod IDs
@@ -22,6 +22,7 @@ import {
// //currentSession, // //currentSession,
// //invalidateSession, // //invalidateSession,
} from 'ember-simple-auth/test-support'; } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | auth methods | update', function (hooks) { module('Acceptance | auth methods | update', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -73,7 +74,7 @@ module('Acceptance | auth methods | update', function (hooks) {
assert.expect(12); assert.expect(12);
instances.authMethod = this.server.create('auth-method', { instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
await visit(`${urls.authMethods}/${instances.authMethod.id}`); await visit(`${urls.authMethods}/${instances.authMethod.id}`);
await click('form [type="button"]:not(:disabled)', 'Activate edit mode'); await click('form [type="button"]:not(:disabled)', 'Activate edit mode');
@@ -25,6 +25,10 @@ import {
invalidateSession, invalidateSession,
} from 'ember-simple-auth/test-support'; } from 'ember-simple-auth/test-support';
import Service from '@ember/service'; import Service from '@ember/service';
import {
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
} from 'api/models/auth-method';
module('Acceptance | authentication', function (hooks) { module('Acceptance | authentication', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -76,15 +80,15 @@ module('Acceptance | authentication', function (hooks) {
scope = { id: orgScope.id, type: orgScope.type }; scope = { id: orgScope.id, type: orgScope.type };
globalAuthMethod = this.server.create('auth-method', { globalAuthMethod = this.server.create('auth-method', {
scope: globalScope, scope: globalScope,
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
}); });
authMethod = this.server.create('auth-method', { authMethod = this.server.create('auth-method', {
scope: orgScope, scope: orgScope,
type: 'password', type: TYPE_AUTH_METHOD_PASSWORD,
}); });
authMethodOIDC = this.server.create('auth-method', { authMethodOIDC = this.server.create('auth-method', {
scope: orgScope, scope: orgScope,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
orgScopeID = orgScope.id; orgScopeID = orgScope.id;
globalAuthMethodID = globalAuthMethod.id; globalAuthMethodID = globalAuthMethod.id;
@@ -10,6 +10,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support'; import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit'; import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs'; import { Response } from 'miragejs';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | managed-groups | create', function (hooks) { module('Acceptance | managed-groups | create', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -40,7 +41,7 @@ module('Acceptance | managed-groups | create', function (hooks) {
}); });
instances.authMethod = this.server.create('auth-method', { instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
instances.managedGroup = this.server.create('managed-group', { instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org, scope: instances.scopes.org,
@@ -10,6 +10,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support'; import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit'; import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs'; import { Response } from 'miragejs';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | managed-groups | delete', function (hooks) { module('Acceptance | managed-groups | delete', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -40,7 +41,7 @@ module('Acceptance | managed-groups | delete', function (hooks) {
}); });
instances.authMethod = this.server.create('auth-method', { instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
instances.managedGroup = this.server.create('managed-group', { instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org, scope: instances.scopes.org,
@@ -8,6 +8,7 @@ import { visit, click, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit'; import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support'; import { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | managed-groups | list', function (hooks) { module('Acceptance | managed-groups | list', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -38,7 +39,7 @@ module('Acceptance | managed-groups | list', function (hooks) {
}); });
instances.authMethod = this.server.create('auth-method', { instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
instances.managedGroup = this.server.create('managed-group', { instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org, scope: instances.scopes.org,
@@ -14,6 +14,7 @@ import {
//currentSession, //currentSession,
//invalidateSession, //invalidateSession,
} from 'ember-simple-auth/test-support'; } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | managed-groups | members', function (hooks) { module('Acceptance | managed-groups | members', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -47,7 +48,7 @@ module('Acceptance | managed-groups | members', function (hooks) {
'auth-method', 'auth-method',
{ {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}, },
'withAccountsAndUsersAndManagedGroups' 'withAccountsAndUsersAndManagedGroups'
); );
@@ -9,6 +9,7 @@ import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support'; import { authenticateSession } from 'ember-simple-auth/test-support';
import a11yAudit from 'ember-a11y-testing/test-support/audit'; import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
module('Acceptance | managed-groups | read', function (hooks) { module('Acceptance | managed-groups | read', function (hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
@@ -39,7 +40,7 @@ module('Acceptance | managed-groups | read', function (hooks) {
}); });
instances.authMethod = this.server.create('auth-method', { instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org, scope: instances.scopes.org,
type: 'oidc', type: TYPE_AUTH_METHOD_OIDC,
}); });
instances.managedGroup = this.server.create('managed-group', { instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org, scope: instances.scopes.org,