feat: 🎸 create get allTags method that includes tag type (#2349)

* feat: 🎸 create getAllTags method that includes tag type

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891

* refactor: 💡 use canonical_tags to get tagCount on a worker

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891

* refactor: 💡 add type to api and config tag list methods

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891

* refactor: 💡 change worker functions to getters

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891
This commit is contained in:
Cameron Perera authored and cameronperera committed 2024-07-16 15:46:05 -05:00
1 parent 1bea4882ca
commit f51124cfdb
3 files changed
+135 -8

No files matched your search

+100
View File
@@ -32,8 +32,108 @@ module('Unit | Model | worker', function (hooks) {
type: 'global',
},
});
await model.createWorkerLed(workerGeneratedAuthToken);
const worker = store.peekRecord('worker', '123abc');
assert.ok(worker);
});
test('it has a `configTagList` method that returns an array of key/value pair objects', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker', {
config_tags: {
tag1: ['value1', 'value2'],
tag2: ['value3'],
},
});
const expected = [
{ key: 'tag1', value: 'value1', type: 'config' },
{ key: 'tag1', value: 'value2', type: 'config' },
{ key: 'tag2', value: 'value3', type: 'config' },
];
assert.deepEqual(model.configTagList, expected);
});
test('it has a `configTagList` method that returns null if there are no config tags', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker');
assert.deepEqual(model.configTagList, null);
});
test('it has a `apiTagList` method that returns an array of key/value pair objects', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker', {
api_tags: {
tag1: ['value1', 'value2'],
tag2: ['value3'],
},
});
const expected = [
{ key: 'tag1', value: 'value1', type: 'api' },
{ key: 'tag1', value: 'value2', type: 'api' },
{ key: 'tag2', value: 'value3', type: 'api' },
];
assert.deepEqual(model.apiTagList, expected);
});
test('it has a `apiTagList` method that returns null if there are no api tags', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker');
assert.deepEqual(model.apiTagList, null);
});
test('it has a `allTags` method that returns an array of key/value pair objects with tag type', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker', {
config_tags: {
tag1: ['value1', 'value2'],
tag2: ['value3'],
},
api_tags: {
tag1: ['value1', 'value2'],
tag2: ['value3'],
},
});
const expected = [
{ key: 'tag1', value: 'value1', type: 'config' },
{ key: 'tag1', value: 'value2', type: 'config' },
{ key: 'tag2', value: 'value3', type: 'config' },
{ key: 'tag1', value: 'value1', type: 'api' },
{ key: 'tag1', value: 'value2', type: 'api' },
{ key: 'tag2', value: 'value3', type: 'api' },
];
assert.deepEqual(model.allTags, expected);
});
test('it has a `allTags` method that returns an empty array if there are no config or api tags', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker');
assert.deepEqual(model.allTags, []);
});
test('tagCount returns the total number of tags', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker', {
canonical_tags: {
tag1: ['value1', 'value2'],
tag2: ['value3'],
},
});
assert.strictEqual(model.tagCount, 3);
});
test('tagCount returns 0 if there are no tags', function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker');
assert.strictEqual(model.tagCount, 0);
});
});