feat: 🎸 add type check helper methods to target model (#1018)

* feat: 🎸 add type check helper methods to target model

* Update addons/api/tests/unit/models/target-test.js

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>

* Update addons/api/tests/unit/models/target-test.js

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
Dharini JeevaandCameron Perera authored and GitHub committed 2022-03-14 09:53:57 -07:00
1 parent a0c3ad7256
commit a9a82079ac
2 files changed
+36

No files matched your search

+16
View File
@@ -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';
}
}
@@ -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);
});
});