From f64f6bfd05b39e241a3baed5e6b7521f384137ed Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 1 Feb 2022 11:14:43 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20new=20fields=20to?= =?UTF-8?q?=20host-set=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new fields to host-set model --- addons/api/addon/models/host-set.js | 6 +++ .../tests/unit/serializers/host-set-test.js | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/addons/api/addon/models/host-set.js b/addons/api/addon/models/host-set.js index b453195d1..2d85fd113 100644 --- a/addons/api/addon/models/host-set.js +++ b/addons/api/addon/models/host-set.js @@ -66,6 +66,12 @@ export default class HostSetModel extends GeneratedHostSetModel { }) host_ids; + // Not sure if re-use this fragment. + @fragmentArray('fragment-string', { + emptyArrayIfMissing: true, // Not sure if should be true. + }) + preferred_endpoints; + // =methods /** diff --git a/addons/api/tests/unit/serializers/host-set-test.js b/addons/api/tests/unit/serializers/host-set-test.js index 9c5c8136e..96335a9f8 100644 --- a/addons/api/tests/unit/serializers/host-set-test.js +++ b/addons/api/tests/unit/serializers/host-set-test.js @@ -13,6 +13,7 @@ module('Unit | Serializer | host set', function (hooks) { description: 'Description', host_catalog_id: '123', version: 1, + preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }], }); const snapshot = record._createSnapshot(); snapshot.adapterOptions = {}; @@ -22,6 +23,7 @@ module('Unit | Serializer | host set', function (hooks) { description: 'Description', host_catalog_id: '123', version: 1, + preferred_endpoints: ['option 1', 'option 2'], }); }); @@ -55,6 +57,7 @@ module('Unit | Serializer | host set', function (hooks) { id: '1', name: 'Host Set 1', host_ids: ['1', '2', '3'], + preferred_endpoints: ['option 1', 'option 2'], }; const normalized = serializer.normalizeSingleResponse( store, @@ -70,6 +73,7 @@ module('Unit | Serializer | host set', function (hooks) { authorized_actions: [], name: 'Host Set 1', host_ids: [{ value: '1' }, { value: '2' }, { value: '3' }], + preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }], }, relationships: {}, }, @@ -101,6 +105,39 @@ module('Unit | Serializer | host set', function (hooks) { name: 'Host Set 1', scope: { scope_id: 'o_123' }, host_ids: [], + preferred_endpoints: [], + }, + relationships: {}, + }, + }); + }); + + test('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'); + const hostSet = store.createRecord('host-set').constructor; + const payload = { + id: '1', + name: 'Host Set 1', + scope: { id: 'o_123' }, + }; + const normalized = serializer.normalizeSingleResponse( + store, + hostSet, + payload + ); + assert.deepEqual(normalized, { + included: [], + data: { + id: '1', + type: 'host-set', + attributes: { + authorized_actions: [], + name: 'Host Set 1', + scope: { scope_id: 'o_123' }, + host_ids: [], + preferred_endpoints: [], }, relationships: {}, },