feat: 🎸 Add basic type support for host-set
Add basic type support for host-set
This commit is contained in:
1 parent
a380bccbf1
commit
26887b3cfe
4 files changed
+147
No files matched your search
@@ -50,4 +50,10 @@ export default class GeneratedHostSetModel extends BaseModel {
|
||||
readOnly: true,
|
||||
})
|
||||
size;
|
||||
|
||||
@attr({
|
||||
description: 'Plugin information for this resource',
|
||||
readOnly: true,
|
||||
})
|
||||
plugin;
|
||||
}
|
||||
@@ -4,6 +4,58 @@ import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||
export default class HostSetModel extends GeneratedHostSetModel {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Returns if the host-set is static or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isStatic() {
|
||||
return this.type === 'static';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the host-set is plugin or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isPlugin() {
|
||||
return this.type === 'plugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a host-set plugin is AWS or not
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isAWS() {
|
||||
return this.compositeType === 'aws';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a host-set plugin is Azure or not.
|
||||
*/
|
||||
get isAzure() {
|
||||
return this.compositeType === 'azure';
|
||||
}
|
||||
|
||||
/**
|
||||
* If a host-set is a plugin return its name,
|
||||
* otherwise returns the host-set type
|
||||
* @type {string}
|
||||
*/
|
||||
get compositeType() {
|
||||
return this.plugin ? this.plugin.name : this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets type, if type is different than static, set plugin name to type
|
||||
*/
|
||||
set compositeType(type) {
|
||||
if (type === 'static') {
|
||||
this.type = 'static';
|
||||
} else {
|
||||
this.type = 'plugin';
|
||||
this.plugin = { name: type };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Host IDs are read-only under normal circumstances. But these can
|
||||
* be persisted via a dedicated call to `addHosts()`.
|
||||
|
||||
@@ -12,4 +12,13 @@ export default Factory.extend({
|
||||
updated_time: () => date.recent(),
|
||||
version: () => datatype.number(),
|
||||
size: () => datatype.number(),
|
||||
plugin: function (i) {
|
||||
if (this.type == 'plugin') {
|
||||
return {
|
||||
id: `pl_${datatype.hexaDecimal(5)}`,
|
||||
name: i % 2 ? 'aws' : 'azure',
|
||||
description: random.words(),
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -129,4 +129,84 @@ module('Unit | Model | host set', function (hooks) {
|
||||
const model = store.peekRecord('host-set', '123abc');
|
||||
await model.removeHost('3');
|
||||
});
|
||||
|
||||
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-set', { type: 'static' });
|
||||
const modelB = store.createRecord('host-set', { 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-set', { type: 'plugin' });
|
||||
const modelStatic = store.createRecord('host-set', { type: 'static' });
|
||||
assert.equal(typeof modelPlugin.isPlugin, 'boolean');
|
||||
assert.true(modelPlugin.isPlugin);
|
||||
assert.false(modelStatic.isPlugin);
|
||||
});
|
||||
|
||||
test('it has isAws and return the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelAws = store.createRecord('host-set', {
|
||||
type: 'plugin',
|
||||
plugin: { name: 'aws' },
|
||||
});
|
||||
const modelRandom = store.createRecord('host-set', {
|
||||
plugin: { name: 'random' },
|
||||
});
|
||||
assert.equal(typeof modelAws.isAWS, 'boolean');
|
||||
assert.true(modelAws.isAWS);
|
||||
assert.false(modelRandom.isAWS);
|
||||
});
|
||||
|
||||
test('it has isAzure and return the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelAzure = store.createRecord('host-set', {
|
||||
type: 'plugin',
|
||||
plugin: { name: 'azure' },
|
||||
});
|
||||
const modelRandom = store.createRecord('host-set', {
|
||||
plugin: { name: 'random' },
|
||||
});
|
||||
assert.equal(typeof modelAzure.isAzure, 'boolean');
|
||||
assert.true(modelAzure.isAzure);
|
||||
assert.false(modelRandom.isAzure);
|
||||
});
|
||||
|
||||
test('get compositeType return expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelPlugin = store.createRecord('host-set', {
|
||||
type: 'plugin',
|
||||
plugin: { name: 'Test name' },
|
||||
});
|
||||
const modelStatic = store.createRecord('host-set', {
|
||||
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-set', {
|
||||
compositeType: 'aws',
|
||||
});
|
||||
const modelStatic = store.createRecord('host-set', {
|
||||
compositeType: 'static',
|
||||
});
|
||||
|
||||
assert.equal(modelPlugin.type, 'plugin');
|
||||
assert.equal(modelPlugin.plugin.name, 'aws');
|
||||
assert.equal(modelStatic.type, 'static');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user