From a9a82079acf9ddfbca150a4b21b5b338302666e7 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 14 Mar 2022 09:53:57 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20type=20check=20hel?= =?UTF-8?q?per=20methods=20to=20target=20model=20(#1018)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 add type check helper methods to target model * Update addons/api/tests/unit/models/target-test.js Co-authored-by: Cameron Perera * Update addons/api/tests/unit/models/target-test.js Co-authored-by: Cameron Perera Co-authored-by: Cameron Perera --- addons/api/addon/models/target.js | 16 ++++++++++++++++ addons/api/tests/unit/models/target-test.js | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/addons/api/addon/models/target.js b/addons/api/addon/models/target.js index 65baaffea..0e15a8842 100644 --- a/addons/api/addon/models/target.js +++ b/addons/api/addon/models/target.js @@ -207,4 +207,20 @@ export default class TargetModel extends GeneratedTargetModel { removeCredentialSource(credentialLibraryID, options) { return this.removeCredentialSources([credentialLibraryID], options); } + + /** + * True if the target type is tcp. + * @type {boolean} + */ + get isTCP() { + return this.type === 'tcp'; + } + + /** + * True if the target type is ssh. + * @type {boolean} + */ + get isSSH() { + return this.type === 'ssh'; + } } diff --git a/addons/api/tests/unit/models/target-test.js b/addons/api/tests/unit/models/target-test.js index e182ccf9f..f3afdb333 100644 --- a/addons/api/tests/unit/models/target-test.js +++ b/addons/api/tests/unit/models/target-test.js @@ -384,4 +384,24 @@ module('Unit | Model | target', function (hooks) { const model = store.peekRecord('target', '123abc'); await model.removeCredentialSource('2'); }); + + test('it has isSSH property and returns the expected values', function (assert) { + assert.expect(2); + const store = this.owner.lookup('service:store'); + const modelSSH = store.createRecord('target', { + type: 'ssh', + }); + assert.true(modelSSH.isSSH); + assert.false(modelSSH.isTCP); + }); + + test('it has isTCP property and returns the expected values', function (assert) { + assert.expect(2); + const store = this.owner.lookup('service:store'); + const modelTCP = store.createRecord('target', { + type: 'tcp', + }); + assert.true(modelTCP.isTCP); + assert.false(modelTCP.isSSH); + }); });