Files
threshold-ui/addons/api/tests/unit/serializers/group-test.js
T
Randall Morey bdabcc119e Refactor base scope fragment (#1166)
* refactor: 💡 migrate managed-group off fragments

* refactor: 💡 migrate credential-store off fragments

* refactor: 💡 migrate credential-library off fragments

* refactor: 💡 migrate account off fragments

* refactor: 💡 convert base model scope field to simple attr

* fix: 🐛 skip broken test
2022-07-18 11:30:53 -07:00

79 lines
2.2 KiB
JavaScript

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: {},
},
});
});
});