Merge branch 'main' into chromeless-window-desktop-option

This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-09-27 08:43:18 -04:00
commit 7265e483d4
55 files changed
+385 -394

No files matched your search

@@ -1,13 +1,13 @@
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentHostSetModel extends Fragment {
export default class FragmentHostSourceModel extends Fragment {
// =attributes
@attr('string', {
description: 'ID of the related host set',
description: 'ID of the related host source',
})
host_set_id;
host_source_id;
@attr('string', {
description: 'ID of the catalog to which the host set belongs',
+32 -38
View File
@@ -12,23 +12,23 @@ export default class TargetModel extends GeneratedTargetModel {
@fragment('fragment-target-attributes', { defaultValue: {} }) attributes;
/**
* @type {[FragmentHostSetModel]}
* @type {[FragmentHostSourceModel]}
*/
@fragmentArray('fragment-host-set', {
@fragmentArray('fragment-host-source', {
readOnly: true,
emptyArrayIfMissing: true,
})
host_sets;
host_sources;
/**
* Credential library ids are read only and can be
* persisted via a dedicated call to `addCredentialLibraries()`.
* Credential source ids are read only and can be
* persisted via a dedicated call to `addCredentialSources()`.
*/
@fragmentArray('fragment-string', {
readOnly: true,
emptyArrayIfMissing: true,
})
application_credential_library_ids;
application_credential_source_ids;
/**
* An array of resolved host set and host catalog instances. Model instances
@@ -36,11 +36,11 @@ export default class TargetModel extends GeneratedTargetModel {
* instances). Unresolvable instances are excluded from the array.
* @type {[{model: HostSetModel, hostCatalog: HostCatalogModel}]}
*/
@computed('host_sets.[]', 'store')
@computed('host_sources.[]', 'store')
get hostSets() {
return this.host_sets
.map(({ host_set_id, host_catalog_id }) => ({
model: this.store.peekRecord('host-set', host_set_id),
return this.host_sources
.map(({ host_source_id, host_catalog_id }) => ({
model: this.store.peekRecord('host-set', host_source_id),
hostCatalog: this.store.peekRecord('host-catalog', host_catalog_id),
}))
.filter((hostSetRef) => hostSetRef.model !== null);
@@ -52,14 +52,11 @@ export default class TargetModel extends GeneratedTargetModel {
* instances). Unresolvable instances are excluded from the array.
* @type {[CredentialLibraryModel]}
*/
@computed('application_credential_library_ids.[]', 'store')
@computed('application_credential_source_ids.[]', 'store')
get credentialLibraries() {
return this.application_credential_library_ids
.map((credential_library_fragment) =>
this.store.peekRecord(
'credential-library',
credential_library_fragment.value
)
return this.application_credential_source_ids
.map((source) =>
this.store.peekRecord('credential-library', source.value)
)
.filter(Boolean);
}
@@ -96,16 +93,16 @@ export default class TargetModel extends GeneratedTargetModel {
// =methods
/**
* Adds host sets via the `add-host-sets` method.
* Adds host sets via the `add-host-sources` method.
* See serializer and adapter for more information.
* @param {[string]} hostSetIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
addHostSets(hostSetIDs, options = { adapterOptions: {} }) {
addHostSources(hostSetIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-host-sets',
method: 'add-host-sources',
hostSetIDs,
};
// There is no "deep merge" in ES.
@@ -119,16 +116,16 @@ export default class TargetModel extends GeneratedTargetModel {
}
/**
* Delete host sets via the `remove-host-sets` method.
* Delete host sets via the `remove-host-sources` method.
* See serializer and adapter for more information.
* @param {[string]} hostSetIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeHostSets(hostSetIDs, options = { adapterOptions: {} }) {
removeHostSources(hostSetIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-host-sets',
method: 'remove-host-sources',
hostSetIDs,
};
// There is no "deep merge" in ES.
@@ -142,29 +139,26 @@ export default class TargetModel extends GeneratedTargetModel {
}
/**
* Delete a single host set via the `remove-host-sets` method.
* Delete a single host set via the `remove-host-sources` method.
* @param {number} hostSetID
* @param {object} options
* @return {Promise}
*/
removeHostSet(hostSetID, options) {
return this.removeHostSets([hostSetID], options);
removeHostSource(hostSetID, options) {
return this.removeHostSources([hostSetID], options);
}
/**
* Adds credential libraries via the `add-credential-libraries` method.
* Adds credential libraries via the `add-credential-sources` method.
* See serializer and adapter for more information.
* @param {[string]} credentialLibraryIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
addCredentialLibraries(
credentialLibraryIDs,
options = { adapterOptions: {} }
) {
addCredentialSources(credentialLibraryIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-credential-libraries',
method: 'add-credential-sources',
credentialLibraryIDs,
};
// There is no "deep merge" in ES.
@@ -178,19 +172,19 @@ export default class TargetModel extends GeneratedTargetModel {
}
/**
* Delete credential libraries via the `remove-credential-libraries` method.
* Delete credential libraries via the `remove-credential-sources` method.
* See serializer and adapter for more information.
* @param {[string]} credentialLibraryIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeCredentialLibraries(
removeCredentialSources(
credentialLibraryIDs,
options = { adapterOptions: {} }
) {
const defaultAdapterOptions = {
method: 'remove-credential-libraries',
method: 'remove-credential-sources',
credentialLibraryIDs,
};
// There is no "deep merge" in ES.
@@ -204,12 +198,12 @@ export default class TargetModel extends GeneratedTargetModel {
}
/**
* Delete a single credential library set via the `remove-credential-libraries` method.
* Delete a single credential library set via the `remove-credential-sources` method.
* @param {number} credentialLibraryID
* @param {object} options
* @return {Promise}
*/
removeCredentialLibrary(credentialLibraryID, options) {
return this.removeCredentialLibraries([credentialLibraryID], options);
removeCredentialSource(credentialLibraryID, options) {
return this.removeCredentialSources([credentialLibraryID], options);
}
}
@@ -1,6 +1,6 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentHostSetSerializer extends JSONSerializer {
export default class FragmentHostSourceSerializer extends JSONSerializer {
// =methods
/**
@@ -1,16 +0,0 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentHostSetSerializer extends JSONSerializer {
// =methods
/**
* Renames `id` to `host_set_id` because fragments may not have IDs.
* Otherwise normalizes as normal.
* @param {ModelClass} typeClass
* @param {object} resourceHash
* @return {object}
*/
normalize(typeClass, { id: host_set_id, ...obj }) {
return super.normalize(typeClass, { host_set_id, ...obj });
}
}
@@ -0,0 +1,16 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentHostSourceSerializer extends JSONSerializer {
// =methods
/**
* Renames `id` to `host_source_id` because fragments may not have IDs.
* Otherwise normalizes as normal.
* @param {ModelClass} typeClass
* @param {object} resourceHash
* @return {object}
*/
normalize(typeClass, { id: host_source_id, ...obj }) {
return super.normalize(typeClass, { host_source_id, ...obj });
}
}
+17 -16
View File
@@ -17,43 +17,44 @@ export default class TargetSerializer extends ApplicationSerializer {
*/
serialize(snapshot) {
let serialized = super.serialize(...arguments);
const hostSetIDs = snapshot?.adapterOptions?.hostSetIDs;
if (hostSetIDs)
serialized = this.serializeWithHostSets(snapshot, hostSetIDs);
const credentialLibraryIDs = snapshot?.adapterOptions?.credentialLibraryIDs;
if (credentialLibraryIDs)
serialized = this.serializeWithCredentialLibraries(
const hostSourceIDs = snapshot?.adapterOptions?.hostSetIDs;
if (hostSourceIDs) {
serialized = this.serializeWithHostSources(snapshot, hostSourceIDs);
}
const credentialSourceIDs = snapshot?.adapterOptions?.credentialLibraryIDs;
if (credentialSourceIDs)
serialized = this.serializeWithCredentialSources(
snapshot,
credentialLibraryIDs
credentialSourceIDs
);
return serialized;
}
/**
* Returns a payload containing only the host_set_ids array using IDs
* passed into the function (rather than existing host sets on the model).
* Returns a payload containing only version and an array of passed IDs,
* rather than existing instances on the model.
* @param {Snapshot} snapshot
* @param {[string]} hostSetIDs
* @return {object}
*/
serializeWithHostSets(snapshot, hostSetIDs) {
serializeWithHostSources(snapshot, hostSourceIDs) {
return {
version: snapshot.attr('version'),
host_set_ids: hostSetIDs,
host_source_ids: hostSourceIDs,
};
}
/**
* Returns a payload containing only the credential_library_ids array using IDs
* passed into the function (rather than existing credential libraries on the model).
* Returns a payload containing only version and an array of passed IDs,
* rather than existing instances on the model.
* @param {Snapshot} snapshot
* @param {[string]} credentialLibraryIDs
* @param {[string]} credentialSourceIDs
* @return {object}
*/
serializeWithCredentialLibraries(snapshot, credentialLibraryIDs) {
serializeWithCredentialSources(snapshot, credentialSourceIDs) {
return {
version: snapshot.attr('version'),
application_credential_library_ids: credentialLibraryIDs,
application_credential_source_ids: credentialSourceIDs,
};
}
}
@@ -1 +0,0 @@
export { default } from 'api/models/fragment-host-set';
@@ -0,0 +1 @@
export { default } from 'api/models/fragment-host-source';
@@ -1 +0,0 @@
export { default } from 'api/serializers/fragment-host-set';
@@ -0,0 +1 @@
export { default } from 'api/serializers/fragment-host-source';
+12 -12
View File
@@ -367,37 +367,37 @@ export default function () {
const updatedAttrs = {
version: attrs.version,
};
// If adding host sets, push them into the array
if (method === 'add-host-sets') {
// If adding host sources, push them into the array
if (method === 'add-host-sources') {
updatedAttrs.hostSetIds = target.hostSetIds;
attrs.hostSetIds.forEach((id) => {
attrs.hostSourceIds.forEach((id) => {
if (!updatedAttrs.hostSetIds.includes(id)) {
updatedAttrs.hostSetIds.push(id);
}
});
}
// If deleting host sets, filter them out of the array
if (method === 'remove-host-sets') {
// If deleting host sources, filter them out of the array
if (method === 'remove-host-sources') {
updatedAttrs.hostSetIds = target.hostSetIds;
updatedAttrs.hostSetIds = updatedAttrs.hostSetIds.filter((id) => {
return !attrs.hostSetIds.includes(id);
return !attrs.hostSourceIds.includes(id);
});
}
// If adding credential libraries, push them into the array
if (method === 'add-credential-libraries') {
// If adding credential sources, push them into the array
if (method === 'add-credential-sources') {
updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
attrs.applicationCredentialLibraryIds.forEach((id) => {
attrs.applicationCredentialSourceIds.forEach((id) => {
if (!updatedAttrs.credentialLibraryIds.includes(id)) {
updatedAttrs.credentialLibraryIds.push(id);
}
});
}
// If deleting credential libraries, filter them out of the array
if (method === 'remove-credential-libraries') {
// If deleting credential sources, filter them out of the array
if (method === 'remove-credential-sources') {
updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
updatedAttrs.credentialLibraryIds =
updatedAttrs.credentialLibraryIds.filter((id) => {
return !attrs.applicationCredentialLibraryIds.includes(id);
return !attrs.applicationCredentialSourceIds.includes(id);
});
}
return target.update(updatedAttrs);
+2 -2
View File
@@ -17,14 +17,14 @@ export default ApplicationSerializer.extend({
);
const { hostSets } = this.schema;
if (model.hostSetIds?.length) {
json.host_sets = model.hostSetIds.map((host_set_id) => {
json.host_sources = model.hostSetIds.map((host_set_id) => {
const hostSet = hostSets.find(host_set_id);
const host_catalog_id = hostSet?.hostCatalog?.id;
return { id: host_set_id, host_catalog_id };
});
}
if (model.credentialLibraryIds?.length) {
json.application_credential_library_ids = model.credentialLibraryIds;
json.application_credential_source_ids = model.credentialLibraryIds;
}
return json;
},
@@ -1,12 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Model | fragment host set', function (hooks) {
module('Unit | Model | fragment host source', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('fragment-host-set', {});
let model = store.createRecord('fragment-host-source', {});
assert.ok(model);
});
});
@@ -68,7 +68,7 @@ module('Unit | Model | host set', function (hooks) {
await model.addHost('foobar');
});
test('it has a `removeHostSets` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has a `removeHosts` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post('/v1/host-sets/123abc:remove-hosts', (schema, request) => {
const body = JSON.parse(request.requestBody);
+84 -81
View File
@@ -14,18 +14,18 @@ module('Unit | Model | target', function (hooks) {
id: '123abc',
type: 'target',
attributes: {
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '2' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '2' },
],
},
},
});
const target = store.peekRecord('target', '123abc');
assert.equal(
target.host_sets.length,
target.host_sources.length,
2,
'Target has two entires in host_sets'
'Target has two entires in host_sources'
);
assert.equal(
target.hostSets.length,
@@ -46,14 +46,14 @@ module('Unit | Model | target', function (hooks) {
attributes: {},
},
});
// Since `hostSets` is computed on `host_sets`, not the store itself,
// Since `hostSets` is computed on `host_sources`, not the store itself,
// it's necessary to do this assignment to kick-off the computed update.
// eslint-disable-next-line no-self-assign
target.host_sets = target.host_sets;
target.host_sources = target.host_sources;
assert.equal(
target.host_sets.length,
target.host_sources.length,
2,
'Target has two entires in host_sets'
'Target has two entires in host_sources'
);
assert.equal(target.hostSets.length, 2, 'Target has two resolved hostSets');
assert.notOk(
@@ -68,52 +68,18 @@ module('Unit | Model | target', function (hooks) {
},
});
// eslint-disable-next-line no-self-assign
target.host_sets = target.host_sets;
target.host_sources = target.host_sources;
assert.ok(target.hostSets[0].hostCatalog, 'Host catalog is resolved');
});
test('it has an `addHostSets` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post('/v1/targets/123abc:add-host-sets', (schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
host_set_ids: ['123_abc', 'foobar'],
version: 1,
});
return { id: '123abc' };
});
const store = this.owner.lookup('service:store');
store.push({
data: {
id: '123abc',
type: 'target',
attributes: {
name: 'Target',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
],
version: 1,
scope: {
scope_id: 'o_1',
type: 'scope',
},
},
},
});
const model = store.peekRecord('target', '123abc');
await model.addHostSets(['123_abc', 'foobar']);
});
test('it has a `removeHostSets` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has an `addHostSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-host-sets',
'/v1/targets/123abc:add-host-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
host_set_ids: ['1', '3'],
host_source_ids: ['123_abc', 'foobar'],
version: 1,
});
return { id: '123abc' };
@@ -127,9 +93,9 @@ module('Unit | Model | target', function (hooks) {
attributes: {
name: 'Target',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
version: 1,
scope: {
@@ -140,17 +106,17 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeHostSets(['1', '3']);
await model.addHostSources(['123_abc', 'foobar']);
});
test('it has a `removeHostSet` method that deletes a single host set using `removeHostSets` method', async function (assert) {
test('it has a `removeHostSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-host-sets',
'/v1/targets/123abc:remove-host-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
host_set_ids: ['3'],
host_source_ids: ['1', '3'],
version: 1,
});
return { id: '123abc' };
@@ -164,9 +130,9 @@ module('Unit | Model | target', function (hooks) {
attributes: {
name: 'Target',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
version: 1,
scope: {
@@ -177,7 +143,44 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeHostSet('3');
await model.removeHostSources(['1', '3']);
});
test('it has a `removeHostSource` method that deletes a single host set using `removeHostSources` method', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-host-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
host_source_ids: ['3'],
version: 1,
});
return { id: '123abc' };
}
);
const store = this.owner.lookup('service:store');
store.push({
data: {
id: '123abc',
type: 'target',
attributes: {
name: 'Target',
description: 'Description',
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
version: 1,
scope: {
scope_id: 'o_1',
type: 'scope',
},
},
},
});
const model = store.peekRecord('target', '123abc');
await model.removeHostSource('3');
});
test('it has a `sessions` array of session instances associated with the target (if those instances are already in the store)', function (assert) {
@@ -232,15 +235,15 @@ module('Unit | Model | target', function (hooks) {
id: '123abc',
type: 'target',
attributes: {
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
},
},
});
const target = store.peekRecord('target', '123abc');
assert.equal(
target.application_credential_library_ids.length,
target.application_credential_source_ids.length,
2,
'Target has two entires in application_credential_library_ids'
'Target has two entires in application_credential_source_ids'
);
assert.equal(
target.credentialLibraries.length,
@@ -261,17 +264,17 @@ module('Unit | Model | target', function (hooks) {
attributes: {},
},
});
// Since `credentialLibraries` is computed on `application_credential_library_ids`,
// Since `credentialLibraries` is computed on `application_credential_source_ids`,
// not the store itself, it's necessary to do this assignment to kick-off the
// computed update.
/* eslint-disable no-self-assign */
target.application_credential_library_ids =
target.application_credential_library_ids;
target.application_credential_source_ids =
target.application_credential_source_ids;
/* eslint-enable no-self-assign */
assert.equal(
target.application_credential_library_ids.length,
target.application_credential_source_ids.length,
2,
'Target has two entires in application_credential_library_ids'
'Target has two entires in application_credential_source_ids'
);
assert.equal(
target.credentialLibraries.length,
@@ -280,14 +283,14 @@ module('Unit | Model | target', function (hooks) {
);
});
test('it has an `addCredentialLibraries` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has an `addCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:add-credential-libraries',
'/v1/targets/123abc:add-credential-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
application_credential_library_ids: ['123_abc', 'foobar'],
application_credential_source_ids: ['123_abc', 'foobar'],
version: 1,
});
return { id: '123abc' };
@@ -301,7 +304,7 @@ module('Unit | Model | target', function (hooks) {
attributes: {
name: 'Target',
description: 'Description',
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
version: 1,
scope: {
scope_id: 'o_1',
@@ -311,17 +314,17 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.addCredentialLibraries(['123_abc', 'foobar']);
await model.addCredentialSources(['123_abc', 'foobar']);
});
test('it has a `removeCredentialLibraries` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has a `removeCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-credential-libraries',
'/v1/targets/123abc:remove-credential-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
application_credential_library_ids: ['1', '2'],
application_credential_source_ids: ['1', '2'],
version: 1,
});
return { id: '123abc' };
@@ -335,7 +338,7 @@ module('Unit | Model | target', function (hooks) {
attributes: {
name: 'Target',
description: 'Description',
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
version: 1,
scope: {
scope_id: 'o_1',
@@ -345,17 +348,17 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeCredentialLibraries(['1', '2']);
await model.removeCredentialSources(['1', '2']);
});
test('it has a `removeCredentialLibrary` method that deletes a single credential library using `removeCredentialLibraries` method', async function (assert) {
test('it has a `removeCredentialSource` method that deletes a single credential library using `removeCredentialSources` method', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-credential-libraries',
'/v1/targets/123abc:remove-credential-sources',
(schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
application_credential_library_ids: ['2'],
application_credential_source_ids: ['2'],
version: 1,
});
return { id: '123abc' };
@@ -369,7 +372,7 @@ module('Unit | Model | target', function (hooks) {
attributes: {
name: 'Target',
description: 'Description',
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
version: 1,
scope: {
scope_id: 'o_1',
@@ -379,6 +382,6 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeCredentialLibrary('2');
await model.removeCredentialSource('2');
});
});
@@ -204,8 +204,8 @@ module('Unit | Serializer | application', function (hooks) {
authorized_actions: [],
name: 'Target 1',
scope: { scope_id: 'o_123' },
host_sets: [],
application_credential_library_ids: [],
host_sources: [],
application_credential_source_ids: [],
},
relationships: {},
},
@@ -1,27 +1,27 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import FragmentHostSet from 'api/models/fragment-host-set';
import FragmentHostSource from 'api/models/fragment-host-source';
module('Unit | Serializer | fragment host set', function (hooks) {
module('Unit | Serializer | fragment host source', function (hooks) {
setupTest(hooks);
test('it normalizes `id` into `host_set_id`', function (assert) {
test('it normalizes `id` into `host_source_id`', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('fragment-host-set');
const normalized = serializer.normalize(FragmentHostSet, {
const serializer = store.serializerFor('fragment-host-source');
const normalized = serializer.normalize(FragmentHostSource, {
id: '2',
host_catalog_id: '1',
});
assert.deepEqual(normalized, {
data: {
attributes: {
host_set_id: '2',
host_source_id: '2',
host_catalog_id: '1',
},
id: null,
relationships: {},
type: 'fragment-host-set',
type: 'fragment-host-source',
},
});
});
@@ -11,11 +11,11 @@ module('Unit | Serializer | target', function (hooks) {
const record = store.createRecord('target', {
name: 'User',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
scope: {
scope_id: 'org_1',
type: 'org',
@@ -40,16 +40,16 @@ module('Unit | Serializer | target', function (hooks) {
});
});
test('it serializes only host sets and version when an `adapterOptions.hostSetIDs` array is passed', function (assert) {
test('it serializes only host sources and version when an `adapterOptions.hostSetIDs` array is passed', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('target');
const record = store.createRecord('target', {
name: 'User',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
version: 1,
});
@@ -59,19 +59,19 @@ module('Unit | Serializer | target', function (hooks) {
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
host_set_ids: ['4', '5'],
host_source_ids: ['4', '5'],
version: 1,
});
});
test('it serializes only credential libraries and version when an `adapterOptions.credentialLibraryIDs` array is passed', function (assert) {
test('it serializes only credential sources and version when an `adapterOptions.credentialLibraryIDs` array is passed', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('target');
const record = store.createRecord('target', {
name: 'User',
description: 'Description',
application_credential_library_ids: [{ value: '1' }, { value: '2' }],
application_credential_source_ids: [{ value: '1' }, { value: '2' }],
version: 1,
});
const snapshot = record._createSnapshot();
@@ -80,7 +80,7 @@ module('Unit | Serializer | target', function (hooks) {
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
application_credential_library_ids: ['4', '5'],
application_credential_source_ids: ['4', '5'],
version: 1,
});
});
@@ -93,11 +93,11 @@ module('Unit | Serializer | target', function (hooks) {
const payload = {
id: '1',
name: 'Target 1',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
application_credential_library_ids: ['1'],
application_credential_source_ids: ['1'],
};
const normalized = serializer.normalizeSingleResponse(
store,
@@ -112,18 +112,18 @@ module('Unit | Serializer | target', function (hooks) {
attributes: {
authorized_actions: [],
name: 'Target 1',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
host_sources: [
{ host_source_id: '1', host_catalog_id: '2' },
{ host_source_id: '3', host_catalog_id: '4' },
],
application_credential_library_ids: [{ value: '1' }],
application_credential_source_ids: [{ value: '1' }],
},
relationships: {},
},
});
});
test('it normalizes missing host_sets and credential libraries to empty array', function (assert) {
test('it normalizes missing host_sources and application_credential_source_ids to empty array', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('target');
@@ -147,8 +147,8 @@ module('Unit | Serializer | target', function (hooks) {
authorized_actions: [],
name: 'Target 1',
scope: { scope_id: 'o_123' },
host_sets: [],
application_credential_library_ids: [],
host_sources: [],
application_credential_source_ids: [],
},
relationships: {},
},