* feat: 🎸 add action dropdown in tags table ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add removeApiTags method to worker ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add tag removal workflow ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * test: 💍 add tests for removing a worker tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * test: 💍 add tests for removing a tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 fix spelling issue ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 use mirage worker serializer to remove empty tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update modal id to class ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 add autofocus to remove tag modal ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 update tags controller attributes ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 create normalizer to add empty object for api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update getter signature ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove unneeded parens ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove type from Hds::Button ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update confirmation modal class name ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add emptyObjectIfMissing model attribute ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 PR feedback ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove default to null in toggleModal ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897
205 lines
6.1 KiB
JavaScript
205 lines
6.1 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import { TYPE_WORKER_PKI } from 'api/models/worker';
|
|
|
|
module('Unit | Model | worker', function (hooks) {
|
|
setupTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
test('it has a `createWorkerLed` method that targets a specific POST API', async function (assert) {
|
|
assert.expect(2);
|
|
const scopeId = 'global';
|
|
const workerGeneratedAuthToken = 'token';
|
|
this.server.post('/workers:create:worker-led', (schema, request) => {
|
|
const body = JSON.parse(request.requestBody);
|
|
assert.deepEqual(body, {
|
|
scope_id: scopeId,
|
|
worker_generated_auth_token: workerGeneratedAuthToken,
|
|
});
|
|
return { id: '123abc' };
|
|
});
|
|
|
|
const store = this.owner.lookup('service:store');
|
|
const model = store.createRecord('worker', {
|
|
type: TYPE_WORKER_PKI,
|
|
scope: {
|
|
scope_id: scopeId,
|
|
type: 'global',
|
|
},
|
|
});
|
|
|
|
await model.createWorkerLed(workerGeneratedAuthToken);
|
|
const worker = store.peekRecord('worker', '123abc');
|
|
|
|
assert.ok(worker);
|
|
});
|
|
|
|
test('it has `setApiTags` method that targets a specific POST API', async function (assert) {
|
|
assert.expect(1);
|
|
const workerId = 'w_123';
|
|
const tags = {
|
|
tag1: ['value1', 'value2'],
|
|
tag2: ['value3'],
|
|
};
|
|
this.server.post(
|
|
`/workers/${workerId}:set-worker-tags`,
|
|
(schema, request) => {
|
|
const body = JSON.parse(request.requestBody);
|
|
assert.deepEqual(body, { api_tags: tags, version: 1 });
|
|
return { id: workerId };
|
|
},
|
|
);
|
|
|
|
const store = this.owner.lookup('service:store');
|
|
store.push({
|
|
data: {
|
|
id: workerId,
|
|
type: 'worker',
|
|
attributes: {
|
|
name: 'fake worker',
|
|
version: 1,
|
|
},
|
|
},
|
|
});
|
|
|
|
const model = store.peekRecord('worker', workerId);
|
|
await model.setApiTags(tags);
|
|
});
|
|
|
|
test('it has a `removeApiTags` method that targets a specific POST API', async function (assert) {
|
|
assert.expect(1);
|
|
const workerId = 'w_123';
|
|
const tags = {
|
|
tag1: ['value1'],
|
|
};
|
|
this.server.post(
|
|
`/workers/${workerId}:remove-worker-tags`,
|
|
(schema, request) => {
|
|
const body = JSON.parse(request.requestBody);
|
|
assert.deepEqual(body, { api_tags: tags, version: 1 });
|
|
return { id: workerId };
|
|
},
|
|
);
|
|
|
|
const store = this.owner.lookup('service:store');
|
|
store.push({
|
|
data: {
|
|
id: workerId,
|
|
type: 'worker',
|
|
attributes: {
|
|
name: 'fake worker',
|
|
version: 1,
|
|
api_tags: tags,
|
|
},
|
|
},
|
|
});
|
|
const model = store.peekRecord('worker', workerId);
|
|
|
|
await model.removeApiTags(tags);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|