Files
threshold-ui/addons/api/tests/unit/serializers/host-test.js
T
0129784322 fix url when user tries to access resource with incorrect url (#1958)
* refactor: 💡 auth-method, account, & managed abilities & routes

* refactor: 💡 credential store resources abilities & routes

* refactor: 💡 group abilities & routes

* refactor: 💡 host-catalog resources abilities & routes

* refactor: 💡 role abilities & routes

* test: 💍 fix route-info-test

* test: 💍 fix host serializer tests

* test: 💍 fix create-test for host-sets

* refactor: 💡 session recording resources abilities & routes

* refactor: 💡 storage bucket abilities & routes

* refactor: 💡 target abilities & routes

* refactor: 💡 user abilities & routes

* refactor: 💡 worker abilities & routes

* refactor: 💡 remove ability changes and add comments

* Update ui/admin/app/utils/route-info.js

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>

* test: 💍 add test cases and rename util file

* refactor: 💡 remove dup file and update imports

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

* docs: ✏️ update comments & remove console.log

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

* Update ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
2023-11-02 16:08:25 -07:00

104 lines
2.9 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | host', function (hooks) {
setupTest(hooks);
test('it serializes host with type static as expected', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host', {
name: 'Host 1',
compositeType: 'static',
description: 'Description',
host_catalog_id: '123',
version: 1,
address: '188e:68a9:b342:c05c:2595:2f46:499c:759f',
});
assert.deepEqual(record.serialize(), {
name: 'Host 1',
description: 'Description',
type: 'static',
host_catalog_id: '123',
version: 1,
attributes: {
address: '188e:68a9:b342:c05c:2595:2f46:499c:759f',
},
});
});
test('it normalizes type static record as expected', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host');
const host = store.createRecord('host').constructor;
const payload = {
id: '1',
name: 'host test',
type: 'static',
authorized_actions: ['no-op', 'read'],
address: '10.0.0.1',
};
const normalized = serializer.normalizeSingleResponse(store, host, payload);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host',
attributes: {
name: 'host test',
type: 'static',
authorized_actions: ['no-op', 'read'],
address: '10.0.0.1',
dns_names: [],
ip_addresses: [],
host_set_ids: [],
},
relationships: {},
},
});
});
test('it normalizes type plugin (aws) record as expected', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host');
const host = store.createRecord('host').constructor;
const payload = {
id: '1',
name: 'host test',
type: 'plugin',
plugin: {
name: 'aws',
},
authorized_actions: ['no-op', 'read'],
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
dns_names: ['test.example.internal', 'test.example.external'],
host_set_ids: ['hst_12345'],
};
const normalized = serializer.normalizeSingleResponse(store, host, payload);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host',
attributes: {
name: 'host test',
type: 'plugin',
authorized_actions: ['no-op', 'read'],
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
dns_names: ['test.example.internal', 'test.example.external'],
plugin: { name: 'aws' },
host_set_ids: ['hst_12345'],
},
relationships: {},
},
});
});
});