* refactor: 💡 convert brokered cred IDs array to simple attribute * fix: 🐛 missing test assertion * fix: 🐛 simplify computed * refactor: 💡 convert host sources array to simple attribute (#1260) * refactor: 💡 convert host source IDs array to simple attribute * fix: 🐛 host source tests * Refactor role fragment arrays (#1262) * refactor: 💡 convert grant strings to regular attribute * refactor: 💡 convert principals array to simple attribute * Update ui/admin/app/routes/scopes/scope/roles/role.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * fix: 🐛 remove unused import Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
108 lines
3.0 KiB
JavaScript
108 lines
3.0 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
module('Unit | Serializer | role', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
test('it serializes roles normally, without grants', function (assert) {
|
|
assert.expect(1);
|
|
const store = this.owner.lookup('service:store');
|
|
const serializer = store.serializerFor('role');
|
|
const record = store.createRecord('role', {
|
|
name: 'User',
|
|
description: 'Description',
|
|
grant_strings: ['foo', 'bar'],
|
|
version: 1,
|
|
});
|
|
const snapshot = record._createSnapshot();
|
|
snapshot.adapterOptions = {};
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
assert.deepEqual(serializedRecord, {
|
|
name: 'User',
|
|
description: 'Description',
|
|
version: 1,
|
|
grant_scope_id: null,
|
|
});
|
|
});
|
|
|
|
test('it serializes only grant strings when `adapterOptions.grantStrings` is set', function (assert) {
|
|
assert.expect(1);
|
|
const store = this.owner.lookup('service:store');
|
|
const serializer = store.serializerFor('role');
|
|
const record = store.createRecord('role', {
|
|
name: 'User',
|
|
description: 'Description',
|
|
grant_strings: ['grant1', 'grant2'],
|
|
version: 1,
|
|
});
|
|
const snapshot = record._createSnapshot();
|
|
snapshot.adapterOptions = {
|
|
grantStrings: ['foo', 'bar'],
|
|
};
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
assert.deepEqual(serializedRecord, {
|
|
grant_strings: ['foo', 'bar'],
|
|
version: 1,
|
|
});
|
|
});
|
|
|
|
test('it normalizes records with array fields', function (assert) {
|
|
assert.expect(1);
|
|
const store = this.owner.lookup('service:store');
|
|
const serializer = store.serializerFor('role');
|
|
const roleModelClass = store.createRecord('role').constructor;
|
|
const payload = {
|
|
id: '1',
|
|
name: 'Role 1',
|
|
grant_strings: ['*', '*'],
|
|
};
|
|
const normalized = serializer.normalizeSingleResponse(
|
|
store,
|
|
roleModelClass,
|
|
payload
|
|
);
|
|
assert.deepEqual(normalized, {
|
|
included: [],
|
|
data: {
|
|
id: '1',
|
|
type: 'role',
|
|
attributes: {
|
|
authorized_actions: [],
|
|
name: 'Role 1',
|
|
grant_strings: ['*', '*'],
|
|
principals: [],
|
|
},
|
|
relationships: {},
|
|
},
|
|
});
|
|
});
|
|
|
|
test('it normalizes missing principals to empty array', function (assert) {
|
|
assert.expect(1);
|
|
const store = this.owner.lookup('service:store');
|
|
const serializer = store.serializerFor('role');
|
|
const role = store.createRecord('role').constructor;
|
|
const payload = {
|
|
id: '1',
|
|
name: 'Role 1',
|
|
scope: { id: 'o_123' },
|
|
};
|
|
const normalized = serializer.normalizeSingleResponse(store, role, payload);
|
|
assert.deepEqual(normalized, {
|
|
included: [],
|
|
data: {
|
|
id: '1',
|
|
type: 'role',
|
|
attributes: {
|
|
authorized_actions: [],
|
|
name: 'Role 1',
|
|
scope: { id: 'o_123', scope_id: 'o_123' },
|
|
principals: [],
|
|
grant_strings: [],
|
|
},
|
|
relationships: {},
|
|
},
|
|
});
|
|
});
|
|
});
|