feat: 🎸 Add new fields to host
Add new fields to host and refactor field address to use no more fragment-host-attribute-model
This commit is contained in:
1 parent
6f8d424bed
commit
f8c4eb470f
5 files changed
+73
-27
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from 'api/models/fragment-host-attributes';
|
||||
@@ -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',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user