Files
threshold-ui/addons/api/tests/unit/serializers/worker-test.js
T
Cameron Perera f9af4f0092 Icu 13897 create remove tag modal (#2377)
* 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
2024-07-16 15:49:30 -05:00

116 lines
3.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | worker', function (hooks) {
setupTest(hooks);
test('it serializes normally', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const record = store.createRecord('worker', {
name: 'worker',
description: 'Description',
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
version: 1,
description: 'Description',
name: 'worker',
});
});
test('it serializes using `adapterOptions.workerGeneratedAuthToken`', function (assert) {
const scopeId = 'global';
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const record = store.createRecord('worker', {
name: 'worker',
description: 'Description',
version: 1,
scope: {
scope_id: scopeId,
type: 'global',
},
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
workerGeneratedAuthToken: '123-abc',
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
scope_id: scopeId,
worker_generated_auth_token: '123-abc',
});
});
test('it serializes using `adapterOptions.apiTags`', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const record = store.createRecord('worker', {
name: 'worker',
api_tags: null,
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
apiTags: {
key: ['value'],
},
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
version: 1,
api_tags: { key: ['value'] },
});
});
test('it normalizes missing `api_tags`, `config_tags`, and `canonical_tags`', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const worker = store.createRecord('worker').constructor;
const payload = {
id: 'w_123',
name: 'hardest worker',
scope: { id: 'global' },
version: 1,
address: 'localhost',
};
const normalized = serializer.normalizeSingleResponse(
store,
worker,
payload,
);
assert.deepEqual(normalized, {
data: {
attributes: {
address: 'localhost',
api_tags: {},
authorized_actions: [],
canonical_tags: {},
config_tags: {},
name: 'hardest worker',
scope: {
id: 'global',
scope_id: 'global',
},
version: 1,
},
id: 'w_123',
relationships: {},
type: 'worker',
},
included: [],
});
});
});