Files
threshold-ui/addons/api/tests/unit/serializers/group-test.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

84 lines
2.3 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 | group', function (hooks) {
setupTest(hooks);
test('it serializes groups normally, without members', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('group');
const record = store.createRecord('group', {
name: 'Group',
description: 'Description',
member_ids: ['1', '2'],
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
name: 'Group',
description: 'Description',
version: 1,
});
});
test('it serializes only host sets and version when an `adapterOptions.memberIDs` array is passed', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('group');
const record = store.createRecord('group', {
name: 'Group',
description: 'Description',
member_ids: ['1', '2'],
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
memberIDs: ['4', '5'],
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
member_ids: ['4', '5'],
version: 1,
});
});
test('it normalizes missing member_ids to empty array', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('group');
const group = store.createRecord('group').constructor;
const payload = {
id: '1',
name: 'Group 1',
scope: { id: 'o_123' },
};
const normalized = serializer.normalizeSingleResponse(
store,
group,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'group',
attributes: {
authorized_actions: [],
name: 'Group 1',
scope: { id: 'o_123', scope_id: 'o_123' },
member_ids: [],
},
relationships: {},
},
});
});
});