feat: 🎸 Add host type basic support

This commit is contained in:
Carlos Alcaide Corvo committed 2022-01-27 10:17:34 -08:00
1 parent d269d27e2c
commit 929b020cf7
3 files changed
+139

No files matched your search

@@ -43,4 +43,10 @@ export default class GeneratedHostModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
@attr({
description: 'Plugin information for this resource.',
readOnly: true,
})
plugin;
}
+53
View File
@@ -7,4 +7,57 @@ export default class HostModel extends GeneratedHostModel {
* @type {FragmentHostAttributesModel}
*/
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
/**
* Returns if the host is static type or not.
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
/**
* Returns if the host is plugin or not.
* @type {boolean}
*/
get isPlugin() {
return this.type === 'plugin';
}
/**
* Returns if host plugin is AWS or not.
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
}
/**
* Returns if hist is Azure or not.
* @type {boolean}
*/
get isAzure() {
return this.compositeType === 'azure';
}
/**
* If host is a plugin return its name,
* otherwise returns the host type
* @type {string}
*/
get compositeType() {
return this.isPlugin ? this.plugin.name : this.type;
}
/**
* Sets type, if type is different than static, sets plugin name to type
*/
set compositeType(type) {
if (type === 'static') {
this.type = 'static';
} else {
this.type = 'plugin';
this.plugin = { name: type };
}
}
}
+80
View File
@@ -22,4 +22,84 @@ module('Unit | Model | host', function (hooks) {
});
assert.equal(model.attributes.address, '127.0.0.1');
});
test('it has isStatic and returns the expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelA = store.createRecord('host', { type: 'static' });
const modelB = store.createRecord('host', { type: 'plugin' });
assert.equal(typeof modelA.isStatic, 'boolean');
assert.true(modelA.isStatic);
assert.false(modelB.isStatic);
});
test('it has isPlugin and returns the expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelPlugin = store.createRecord('host', { type: 'plugin' });
const modelStatic = store.createRecord('host', { type: 'static' });
assert.equal(typeof modelPlugin.isPlugin, 'boolean');
assert.true(modelPlugin.isPlugin);
assert.false(modelStatic.isPlugin);
});
test('it has isAWS and returns the expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelAws = store.createRecord('host', {
type: 'plugin',
plugin: { name: 'aws' },
});
const modelRandom = store.createRecord('host', {
plugin: { name: 'random' },
});
assert.equal(typeof modelAws.isAWS, 'boolean');
assert.true(modelAws.isAWS);
assert.false(modelRandom.isAWS);
});
test('it has isAzure and returns the expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelAzure = store.createRecord('host', {
type: 'plugin',
plugin: { name: 'azure' },
});
const modelRandom = store.createRecord('host', {
plugin: { name: 'random' },
});
assert.equal(typeof modelAzure.isAzure, 'boolean');
assert.true(modelAzure.isAzure);
assert.false(modelRandom.isAzure);
});
test('get compositeType returns expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelPlugin = store.createRecord('host', {
type: 'plugin',
plugin: { name: 'Test name' },
});
const modelStatic = store.createRecord('host', {
type: 'static',
});
assert.equal(typeof modelPlugin.compositeType, 'string');
assert.equal(modelPlugin.compositeType, 'Test name');
assert.equal(modelStatic.compositeType, 'static');
});
test('set compositeType sets expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelPlugin = store.createRecord('host', {
compositeType: 'aws',
});
const modelStatic = store.createRecord('host', {
compositeType: 'static',
});
assert.equal(modelPlugin.type, 'plugin');
assert.equal(modelPlugin.plugin.name, 'aws');
assert.equal(modelStatic.type, 'static');
});
});