From f8c4eb470f5f8517f3f3bb8f3862aa972cd47fb7 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Mon, 7 Feb 2022 09:48:51 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20new=20fields=20to?= =?UTF-8?q?=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new fields to host and refactor field address to use no more fragment-host-attribute-model --- addons/api/addon/generated/models/host.js | 18 +++++++ .../addon/models/fragment-host-attributes.js | 9 ---- addons/api/addon/models/host.js | 21 +++++--- .../app/models/fragment-host-attributes.js | 1 - .../api/tests/unit/serializers/host-test.js | 51 +++++++++++++++---- 5 files changed, 73 insertions(+), 27 deletions(-) delete mode 100644 addons/api/addon/models/fragment-host-attributes.js delete mode 100644 addons/api/app/models/fragment-host-attributes.js diff --git a/addons/api/addon/generated/models/host.js b/addons/api/addon/generated/models/host.js index 08efa6397..3873070f2 100644 --- a/addons/api/addon/generated/models/host.js +++ b/addons/api/addon/generated/models/host.js @@ -44,9 +44,27 @@ export default class GeneratedHostModel extends BaseModel { }) version; + @attr({ + description: 'Attributes specific to the host type', + }) + attributes; + + @attr('string', { + description: 'The address (DNS or IP name) used to reach the host', + isNestedAttribute: true, + }) + address; + @attr({ description: 'Plugin information for this resource.', readOnly: true, }) plugin; + + @attr('string', { + description: '', + readOnly: true, + isNestedAttribute: true, + }) + external_id; } diff --git a/addons/api/addon/models/fragment-host-attributes.js b/addons/api/addon/models/fragment-host-attributes.js deleted file mode 100644 index 3f0ac9073..000000000 --- a/addons/api/addon/models/fragment-host-attributes.js +++ /dev/null @@ -1,9 +0,0 @@ -import Fragment from 'ember-data-model-fragments/fragment'; -import { attr } from '@ember-data/model'; - -export default class FragmentHostAttributesModel extends Fragment { - @attr('string', { - description: 'The address (DNS or IP name) used to reach the host', - }) - address; -} diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 14acc4d27..133464027 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -1,12 +1,21 @@ import GeneratedHostModel from '../generated/models/host'; -import { fragment } from 'ember-data-model-fragments/attributes'; +import { fragmentArray } from 'ember-data-model-fragments/attributes'; export default class HostModel extends GeneratedHostModel { - /** - * Attributes of this resource, if any, represented as a JSON fragment. - * @type {FragmentHostAttributesModel} - */ - @fragment('fragment-host-attributes', { defaultValue: {} }) attributes; + @fragmentArray('fragment-string', { + readOnly: true, + emptyArrayIfMissing: true, + isNestedAttribute: true, + }) + ip_addresses; + + // Aws specific + @fragmentArray('fragment-string', { + readOnly: true, + emptyArrayIfMissing: true, + isNestedAttribute: true, + }) + dns_names; /** * True if the host is static. diff --git a/addons/api/app/models/fragment-host-attributes.js b/addons/api/app/models/fragment-host-attributes.js deleted file mode 100644 index 201efcb7a..000000000 --- a/addons/api/app/models/fragment-host-attributes.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'api/models/fragment-host-attributes'; diff --git a/addons/api/tests/unit/serializers/host-test.js b/addons/api/tests/unit/serializers/host-test.js index 4c531ca82..e6361984c 100644 --- a/addons/api/tests/unit/serializers/host-test.js +++ b/addons/api/tests/unit/serializers/host-test.js @@ -4,19 +4,48 @@ import { setupTest } from 'ember-qunit'; module('Unit | Serializer | host', function (hooks) { setupTest(hooks); - test('it exists', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('host'); - - assert.ok(serializer); + test('it serializes host with type static as expected', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const record = store.createRecord('host', { + name: 'Host 1', + compositeType: 'static', + description: 'Description', + host_catalog_id: '123', + version: 1, + address: '188e:68a9:b342:c05c:2595:2f46:499c:759f', + }); + assert.deepEqual(record.serialize(), { + name: 'Host 1', + description: 'Description', + type: 'static', + host_catalog_id: '123', + version: 1, + attributes: { + address: '188e:68a9:b342:c05c:2595:2f46:499c:759f', + }, + }); }); - test('it serializes records', function (assert) { - let store = this.owner.lookup('service:store'); - let record = store.createRecord('host', {}); + test('it serializes host with type plugin as expected', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const recordAws = store.createRecord('host', { + name: 'Host 2', + description: 'Description', + host_catalog_id: '123', + compositeType: 'aws', + address: '188e:68a9:b342:c05c:2595:2f46:499c:759f', + }); - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); + assert.deepEqual(recordAws.serialize(), { + name: 'Host 2', + description: 'Description', + host_catalog_id: '123', + type: 'plugin', + attributes: { + address: '188e:68a9:b342:c05c:2595:2f46:499c:759f', + }, + }); }); });