Add all the new fields. Refactor serializer to fit new changes. Work in progress with normalize

This commit is contained in:
Carlos Alcaide Corvo committed 2022-02-03 11:27:08 -08:00
1 parent f64f6bfd05
commit 5e918cdddc
4 files changed
+117 -13

No files matched your search

@@ -4,21 +4,29 @@ import { setupTest } from 'ember-qunit';
module('Unit | Serializer | host set', function (hooks) {
setupTest(hooks);
// DONE // Serializes host sets normally, no host_ids, no plugin.
// DONE // Serializes host sets only host_ids.
// DONE // Serializes host sets as expected for a Aws plugin.
// DONE // Serializes host sets as expected for Azure plugin.
// WIP // Normalizes records with array fields.
// ? // Normalizes records missing host_ids to empty array.
// ? // Normalizes missing preferred_endpoints to empty array.
// ? // Normalizes records with array fields, static.
// ? // Normalizes records with array fields, aws.
// ? // Normalizes records with array fields, azure.
test('it serializes host sets normally, without host_ids', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const record = store.createRecord('host-set', {
name: 'Host Set 1',
compositeType: 'static',
description: 'Description',
host_catalog_id: '123',
version: 1,
preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }],
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
assert.deepEqual(record.serialize(), {
name: 'Host Set 1',
description: 'Description',
host_catalog_id: '123',
@@ -48,7 +56,55 @@ module('Unit | Serializer | host set', function (hooks) {
});
});
test('it normalizes records with array fields', function (assert) {
test('it serializes host sets as expected for Aws plugin', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-set', {
name: 'Host Set 1',
compositeType: 'aws',
description: 'Description',
host_catalog_id: '123',
version: 1,
preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }],
filters: [{ value: 'filter 1' }, { value: 'filter 2' }],
});
assert.deepEqual(record.serialize(), {
name: 'Host Set 1',
description: 'Description',
host_catalog_id: '123',
version: 1,
preferred_endpoints: ['option 1', 'option 2'],
attributes: {
filters: ['filter 1', 'filter 2'],
},
});
});
test('it serializes host sets as expected for Azure plugin', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-set', {
name: 'Host Set 1',
compositeType: 'azure',
description: 'Description',
host_catalog_id: '123',
version: 1,
preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }],
filter: 'filter 1 && filter 2',
});
assert.deepEqual(record.serialize(), {
name: 'Host Set 1',
description: 'Description',
host_catalog_id: '123',
version: 1,
preferred_endpoints: ['option 1', 'option 2'],
attributes: {
filter: 'filter 1 && filter 2',
},
});
});
test.skip('it normalizes records with array fields', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
@@ -56,6 +112,7 @@ module('Unit | Serializer | host set', function (hooks) {
const payload = {
id: '1',
name: 'Host Set 1',
type: 'static',
host_ids: ['1', '2', '3'],
preferred_endpoints: ['option 1', 'option 2'],
};
@@ -64,12 +121,14 @@ module('Unit | Serializer | host set', function (hooks) {
hostSetModelClass,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host-set',
attributes: {
type: 'static',
authorized_actions: [],
name: 'Host Set 1',
host_ids: [{ value: '1' }, { value: '2' }, { value: '3' }],
@@ -80,7 +139,7 @@ module('Unit | Serializer | host set', function (hooks) {
});
});
test('it normalizes missing host_ids to empty array', function (assert) {
test.skip('it normalizes missing host_ids to empty array', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
@@ -112,7 +171,7 @@ module('Unit | Serializer | host set', function (hooks) {
});
});
test('it normalizes missing preferred_endpoints to empty array', function (assert) {
test.skip('it normalizes missing preferred_endpoints to empty array', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');