Refactor some readOnly attributes to have no type. Stop nesting plugin type fields. Refactor serializer/normalizer tests

This commit is contained in:
Carlos Alcaide Corvo committed 2022-02-09 08:55:10 -08:00
1 parent 75f75878a1
commit 46246441aa
2 files changed
+19 -56

No files matched your search

+10 -11
View File
@@ -1,34 +1,33 @@
import GeneratedHostModel from '../generated/models/host';
import { attr } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
export default class HostModel extends GeneratedHostModel {
// =attributes (nested under attributes)
@fragmentArray('fragment-string', {
readOnly: true,
emptyArrayIfMissing: true,
isNestedAttribute: true,
})
ip_addresses;
// =attributes
// Static specific fields
@attr('string', {
description: 'The address (DNS or IP name) used to reach the host',
isNestedAttribute: true,
})
address;
// Plugin specific fields
@attr({
readOnly: true,
emptyArrayIfMissing: true,
})
ip_addresses;
@attr('string', {
description: '',
readOnly: true,
isNestedAttribute: true,
})
external_id;
// Aws specific
@fragmentArray('fragment-string', {
@attr({
readOnly: true,
emptyArrayIfMissing: true,
isNestedAttribute: true,
})
dns_names;
+9 -45
View File
@@ -27,29 +27,7 @@ module('Unit | Serializer | host', function (hooks) {
});
});
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',
});
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',
},
});
});
test('it normalizes type static record', function (assert) {
test('it normalizes type static record as expected', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host');
@@ -58,9 +36,8 @@ module('Unit | Serializer | host', function (hooks) {
id: '1',
name: 'host test',
type: 'static',
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
authorized_actions: ['no-op', 'read'],
dns_names: ['test.example.internal', 'test.example.external'],
address: '10.0.0.1',
};
const normalized = serializer.normalizeSingleResponse(store, host, payload);
assert.deepEqual(normalized, {
@@ -72,22 +49,16 @@ module('Unit | Serializer | host', function (hooks) {
name: 'host test',
type: 'static',
authorized_actions: ['no-op', 'read'],
dns_names: [
{ value: 'test.example.internal' },
{ value: 'test.example.external' },
],
ip_addresses: [
{ value: '10.0.0.1' },
{ value: '10.0.0.2' },
{ value: '10.0.0.3' },
],
address: '10.0.0.1',
dns_names: [],
ip_addresses: [],
},
relationships: {},
},
});
});
test('it normalizes type plugin (aws) record', function (assert) {
test('it normalizes type plugin (aws) record as expected', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host');
@@ -99,8 +70,8 @@ module('Unit | Serializer | host', function (hooks) {
plugin: {
name: 'aws',
},
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
authorized_actions: ['no-op', 'read'],
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
dns_names: ['test.example.internal', 'test.example.external'],
};
const normalized = serializer.normalizeSingleResponse(store, host, payload);
@@ -113,15 +84,8 @@ module('Unit | Serializer | host', function (hooks) {
name: 'host test',
type: 'plugin',
authorized_actions: ['no-op', 'read'],
dns_names: [
{ value: 'test.example.internal' },
{ value: 'test.example.external' },
],
ip_addresses: [
{ value: '10.0.0.1' },
{ value: '10.0.0.2' },
{ value: '10.0.0.3' },
],
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
dns_names: ['test.example.internal', 'test.example.external'],
plugin: { name: 'aws' },
},
relationships: {},