From 226475a47dc24b772a1489ea3d0894e3a9aa84d0 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Tue, 12 Apr 2022 16:16:51 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20"worker=5Ffilter"?= =?UTF-8?q?=20attribute=20to=20target=20model=20(#1049)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 Add "worker_filter" attribute to target model ✅ Closes: ICU-3887 * feat: 🎸 Add missing attribute description for worker_filter * feat: 🎸 Update worker_filter description Co-authored-by: Dharini Jeeva --- addons/api/addon/generated/models/target.js | 6 ++ .../api/tests/unit/serializers/target-test.js | 65 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/addons/api/addon/generated/models/target.js b/addons/api/addon/generated/models/target.js index 4bf84649f..b8c8829f4 100644 --- a/addons/api/addon/generated/models/target.js +++ b/addons/api/addon/generated/models/target.js @@ -34,6 +34,12 @@ export default class GeneratedTargetModel extends BaseModel { }) session_connection_limit; + @attr('string', { + description: + 'Optional boolean expression to filter the workers that are allowed to satisfy this request.', + }) + worker_filter; + @attr('date', { description: 'The time this resource was created\nOutput only.', readOnly: true, diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js index d384e2cee..d76501816 100644 --- a/addons/api/tests/unit/serializers/target-test.js +++ b/addons/api/tests/unit/serializers/target-test.js @@ -35,6 +35,7 @@ module('Unit | Serializer | target', function (hooks) { scope_id: 'org_1', session_max_seconds: 28800, session_connection_limit: 1, + worker_filter: null, attributes: { default_port: 1234, }, @@ -86,6 +87,38 @@ module('Unit | Serializer | target', function (hooks) { }); }); + test('it serializes the worker_filter attribute if present', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('target'); + const record = store.createRecord('target', { + name: 'User', + description: 'Description', + version: 1, + type: 'ssh', + worker_filter: 'worker', + default_port: 1234, + scope: { + scope_id: 'org_1', + }, + }); + const snapshot = record._createSnapshot(); + const serializedRecord = serializer.serialize(snapshot); + assert.deepEqual(serializedRecord, { + name: 'User', + description: 'Description', + version: 1, + type: 'ssh', + scope_id: 'org_1', + session_max_seconds: 28800, + session_connection_limit: 1, + worker_filter: 'worker', + attributes: { + default_port: 1234, + }, + }); + }); + test('it normalizes records with array fields', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); @@ -189,4 +222,36 @@ module('Unit | Serializer | target', function (hooks) { }, }); }); + + test('it normalizes the worker_filter attribute if present', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('target'); + const target = store.createRecord('target').constructor; + const payload = { + id: '1', + name: 'Target 1', + worker_filter: 'worker', + }; + const normalized = serializer.normalizeSingleResponse( + store, + target, + payload + ); + assert.deepEqual(normalized, { + included: [], + data: { + id: '1', + type: 'target', + attributes: { + authorized_actions: [], + name: 'Target 1', + host_sources: [], + application_credential_source_ids: [], + worker_filter: 'worker', + }, + relationships: {}, + }, + }); + }); });