Icu 6657 auth method model fragments refactor (#1507)

* refactor: 💡 Remove fragment usage for arrays in auth method
* chore: 🤖 Remove ember-data-model-fragments

✅ Closes: ICU-6657
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-12-02 14:29:53 -05:00
1 parent f8429b15e9
commit c3d9fd8fc5
32 files changed
+161 -341

No files matched your search

@@ -1,35 +0,0 @@
import Application from '@ember/application';
import { initialize } from 'dummy/initializers/fragment-auth-method-attributes-account-claim-map-serializer';
import { module, test } from 'qunit';
import Resolver from 'ember-resolver';
import { run } from '@ember/runloop';
module(
'Unit | Initializer | fragment-auth-method-attributes-account-claim-map-serializer',
function (hooks) {
hooks.beforeEach(function () {
this.TestApplication = class TestApplication extends Application {};
this.TestApplication.initializer({
name: 'initializer under test',
initialize,
});
this.application = this.TestApplication.create({
autoboot: false,
Resolver,
});
});
hooks.afterEach(function () {
run(this.application, 'destroy');
});
// TODO: Replace this with your real tests.
test('it works', async function (assert) {
await this.application.boot();
assert.ok(true);
});
}
);
@@ -1,32 +0,0 @@
import Application from '@ember/application';
import { initialize } from 'dummy/initializers/fragment-string';
import { module, test } from 'qunit';
import Resolver from 'ember-resolver';
import { run } from '@ember/runloop';
module('Unit | Initializer | fragment-string', function (hooks) {
hooks.beforeEach(function () {
this.TestApplication = class TestApplication extends Application {};
this.TestApplication.initializer({
name: 'initializer under test',
initialize,
});
this.application = this.TestApplication.create({
autoboot: false,
Resolver,
});
});
hooks.afterEach(function () {
run(this.application, 'destroy');
});
// TODO: Replace this with your real tests.
test('it works', async function (assert) {
await this.application.boot();
assert.ok(true);
});
});
@@ -1,18 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Model | fragment auth method attributes account claim map',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord(
'fragment-auth-method-attributes-account-claim-map',
{}
);
assert.ok(model);
});
}
);
@@ -1,12 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Model | fragment string', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('fragment-string', {});
assert.ok(model);
});
});
@@ -157,16 +157,10 @@ module('Unit | Serializer | auth method', function (hooks) {
this.server.get('/v1/auth-methods/oidc123', () => ({
attributes: {
account_claim_maps: ['from=to', 'foo=bar'],
claims_scopes: [{ value: 'profile' }, { value: 'email' }],
signing_algorithms: [{ value: 'RS256' }, { value: 'RS384' }],
allowed_audiences: [
{ value: 'www.alice.com' },
{ value: 'www.alice.com/admin' },
],
idp_ca_certs: [
{ value: 'certificate-1234' },
{ value: 'certificate-5678' },
],
claims_scopes: ['profile', 'email'],
signing_algorithms: ['RS256', 'RS384'],
allowed_audiences: ['www.alice.com', 'www.alice.com/admin'],
idp_ca_certs: ['certificate-1234', 'certificate-5678'],
api_url_prefix: apiUrlPrefix,
client_id: clientId,
client_secret: clientSecret,
@@ -181,12 +175,31 @@ module('Unit | Serializer | auth method', function (hooks) {
}));
const record = await store.findRecord('auth-method', 'oidc123');
const { account_claim_maps } = record;
assert.strictEqual(account_claim_maps.firstObject.from, 'from');
assert.strictEqual(account_claim_maps.firstObject.to, 'to');
assert.strictEqual(account_claim_maps.lastObject.from, 'foo');
assert.strictEqual(account_claim_maps.lastObject.to, 'bar');
const {
account_claim_maps,
claims_scopes,
allowed_audiences,
signing_algorithms,
idp_ca_certs,
} = record;
console.log(record);
assert.deepEqual(account_claim_maps, [
{ from: 'from', to: 'to' },
{ from: 'foo', to: 'bar' },
]);
assert.deepEqual(claims_scopes, [{ value: 'profile' }, { value: 'email' }]);
assert.deepEqual(allowed_audiences, [
{ value: 'www.alice.com' },
{ value: 'www.alice.com/admin' },
]);
assert.deepEqual(signing_algorithms, [
{ value: 'RS256' },
{ value: 'RS384' },
]);
assert.deepEqual(idp_ca_certs, [
{ value: 'certificate-1234' },
{ value: 'certificate-5678' },
]);
assert.strictEqual(record.api_url_prefix, apiUrlPrefix);
assert.strictEqual(record.client_id, clientId);
assert.strictEqual(record.client_secret, clientSecret);
@@ -1,49 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | fragment string', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('fragment-string');
assert.ok(serializer);
});
test('it serializes records', function (assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('fragment-string', {
value: 'string value',
});
let serializedRecord = record.serialize();
assert.strictEqual(serializedRecord, 'string value');
});
test('it normalizes records', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('fragment-string');
const modelClass = store.createRecord('fragment-string').constructor;
const payload = 'string value';
const normalized = serializer.normalizeSingleResponse(
store,
modelClass,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: null,
type: 'fragment-string',
attributes: {
value: 'string value',
},
relationships: {},
},
});
});
});
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Transform | account claim map array', function (hooks) {
setupTest(hooks);
test('it deserializes an array of account claims', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:account-claim-map-array');
const deserialized = transform.deserialize(['oid=sub', 'full_name=name']);
assert.deepEqual(deserialized, [
{ from: 'oid', to: 'sub' },
{ from: 'full_name', to: 'name' },
]);
});
test('it serializes an array of account claims', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:account-claim-map-array');
const serialized = transform.serialize([
{ from: 'oid', to: 'sub' },
{ from: 'full_name', to: 'name' },
]);
assert.deepEqual(serialized, ['oid=sub', 'full_name=name']);
});
});