Move new fields attributes from host generated model to plain host model. Add normalization tests
This commit is contained in:
1 parent
f8c4eb470f
commit
12277c5557
3 files changed
+75
-18
No files matched your search
@@ -44,27 +44,9 @@ 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,7 +1,9 @@
|
||||
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,
|
||||
@@ -9,6 +11,19 @@ export default class HostModel extends GeneratedHostModel {
|
||||
})
|
||||
ip_addresses;
|
||||
|
||||
@attr('string', {
|
||||
description: 'The address (DNS or IP name) used to reach the host',
|
||||
isNestedAttribute: true,
|
||||
})
|
||||
address;
|
||||
|
||||
@attr('string', {
|
||||
description: '',
|
||||
readOnly: true,
|
||||
isNestedAttribute: true,
|
||||
})
|
||||
external_id;
|
||||
|
||||
// Aws specific
|
||||
@fragmentArray('fragment-string', {
|
||||
readOnly: true,
|
||||
|
||||
@@ -48,4 +48,64 @@ module('Unit | Serializer | host', function (hooks) {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes type static record', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('host');
|
||||
const host = store.createRecord('host').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'host test',
|
||||
type: 'static',
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(store, host, payload);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'host',
|
||||
attributes: {
|
||||
name: 'host test',
|
||||
type: 'static',
|
||||
authorized_actions: [],
|
||||
dns_names: [],
|
||||
ip_addresses: [],
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes type plugin (aws) record', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('host');
|
||||
const host = store.createRecord('host').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'host test',
|
||||
type: 'plugin',
|
||||
plugin: {
|
||||
name: 'aws',
|
||||
},
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(store, host, payload);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'host',
|
||||
attributes: {
|
||||
name: 'host test',
|
||||
type: 'plugin',
|
||||
authorized_actions: [],
|
||||
dns_names: [],
|
||||
ip_addresses: [],
|
||||
plugin: { name: 'aws' },
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user