2021-10-28 08:30:28 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
|
2021-11-04 16:05:11 -07:00
|
|
|
module('Unit | Serializer | Managed group', function (hooks) {
|
2021-10-28 08:30:28 -07:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2021-11-01 16:30:54 -07:00
|
|
|
test('it serializes correctly on create with no filter provided', function (assert) {
|
2021-10-28 08:30:28 -07:00
|
|
|
assert.expect(1);
|
|
|
|
|
const store = this.owner.lookup('service:store');
|
2021-11-04 16:05:11 -07:00
|
|
|
const serializer = store.serializerFor('managed-group');
|
|
|
|
|
const record = store.createRecord('managed-group', {
|
2021-10-28 08:30:28 -07:00
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
member_ids: ['1', '2'],
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
|
|
|
|
});
|
|
|
|
|
const snapshot = record._createSnapshot();
|
|
|
|
|
snapshot.adapterOptions = {};
|
|
|
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
|
|
|
assert.deepEqual(serializedRecord, {
|
|
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
2021-11-02 08:42:55 -07:00
|
|
|
type: null,
|
2021-11-01 12:26:22 -07:00
|
|
|
attributes: {
|
2021-11-01 16:30:54 -07:00
|
|
|
filter: null,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it serializes correctly on create when filter provided', function (assert) {
|
|
|
|
|
assert.expect(1);
|
|
|
|
|
const store = this.owner.lookup('service:store');
|
2021-11-04 16:05:11 -07:00
|
|
|
const serializer = store.serializerFor('managed-group');
|
|
|
|
|
const record = store.createRecord('managed-group', {
|
2021-11-01 16:30:54 -07:00
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
member_ids: ['1', '2'],
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
2021-11-05 10:32:32 -07:00
|
|
|
type: 'oidc',
|
2021-11-01 16:30:54 -07:00
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const snapshot = record._createSnapshot();
|
|
|
|
|
snapshot.adapterOptions = {};
|
|
|
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
|
|
|
assert.deepEqual(serializedRecord, {
|
|
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
2021-11-05 10:32:32 -07:00
|
|
|
type: 'oidc',
|
2021-11-01 16:30:54 -07:00
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-05 08:55:22 -07:00
|
|
|
test('it does not serialize version when it has null or undefined value', function (assert) {
|
|
|
|
|
assert.expect(1);
|
|
|
|
|
const store = this.owner.lookup('service:store');
|
|
|
|
|
const serializer = store.serializerFor('managed-group');
|
|
|
|
|
store.push({
|
|
|
|
|
data: {
|
|
|
|
|
id: '1',
|
|
|
|
|
type: 'managed-group',
|
|
|
|
|
attributes: {
|
|
|
|
|
name: 'Group Test',
|
|
|
|
|
description: 'Description for the test',
|
|
|
|
|
member_ids: ['1', '2'],
|
|
|
|
|
version: undefined,
|
|
|
|
|
auth_method_id: '1234',
|
|
|
|
|
type: 'oidc',
|
|
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const record = store.peekRecord('managed-group', '1');
|
|
|
|
|
const snapshot = record._createSnapshot();
|
|
|
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
|
|
|
assert.deepEqual(serializedRecord, {
|
|
|
|
|
name: 'Group Test',
|
|
|
|
|
description: 'Description for the test',
|
|
|
|
|
auth_method_id: '1234',
|
|
|
|
|
type: 'oidc',
|
|
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-01 16:30:54 -07:00
|
|
|
test('it does not serialize readOnly attributes', function (assert) {
|
|
|
|
|
assert.expect(1);
|
|
|
|
|
const store = this.owner.lookup('service:store');
|
2021-11-04 16:05:11 -07:00
|
|
|
const serializer = store.serializerFor('managed-group');
|
|
|
|
|
const record = store.createRecord('managed-group', {
|
2021-11-01 16:30:54 -07:00
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
|
|
|
|
member_ids: ['1', '2'],
|
|
|
|
|
created_time: Date.now(),
|
|
|
|
|
updated_time: Date.now(),
|
|
|
|
|
});
|
|
|
|
|
const snapshot = record._createSnapshot();
|
|
|
|
|
snapshot.adapterOptions = {};
|
|
|
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
|
|
|
assert.deepEqual(serializedRecord, {
|
|
|
|
|
name: 'Group',
|
|
|
|
|
description: 'Description',
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
2021-11-02 08:42:55 -07:00
|
|
|
type: null,
|
2021-11-01 16:30:54 -07:00
|
|
|
attributes: {
|
|
|
|
|
filter: null,
|
2021-11-01 12:26:22 -07:00
|
|
|
},
|
2021-10-28 08:30:28 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-28 11:28:21 -07:00
|
|
|
test('it serializes correctly on update', function (assert) {
|
2021-10-28 08:30:28 -07:00
|
|
|
assert.expect(1);
|
|
|
|
|
const store = this.owner.lookup('service:store');
|
2021-11-04 16:05:11 -07:00
|
|
|
const serializer = store.serializerFor('managed-group');
|
2021-10-28 11:28:21 -07:00
|
|
|
store.push({
|
|
|
|
|
data: {
|
|
|
|
|
id: '1',
|
2021-11-04 16:05:11 -07:00
|
|
|
type: 'managed-group',
|
2021-10-28 11:28:21 -07:00
|
|
|
attributes: {
|
|
|
|
|
name: 'Group Test',
|
|
|
|
|
description: 'Description for the test',
|
|
|
|
|
member_ids: ['1', '2'],
|
|
|
|
|
version: 1,
|
|
|
|
|
auth_method_id: '1234',
|
2021-11-04 15:06:42 -07:00
|
|
|
type: 'oidc',
|
2021-11-01 12:26:22 -07:00
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
2021-10-28 11:28:21 -07:00
|
|
|
},
|
|
|
|
|
},
|
2021-10-28 08:30:28 -07:00
|
|
|
});
|
2021-11-04 16:05:11 -07:00
|
|
|
const record = store.peekRecord('managed-group', '1');
|
2021-10-28 08:30:28 -07:00
|
|
|
const snapshot = record._createSnapshot();
|
|
|
|
|
const serializedRecord = serializer.serialize(snapshot);
|
|
|
|
|
assert.deepEqual(serializedRecord, {
|
2021-10-28 11:28:21 -07:00
|
|
|
name: 'Group Test',
|
|
|
|
|
description: 'Description for the test',
|
2021-10-28 08:30:28 -07:00
|
|
|
version: 1,
|
2021-10-28 11:28:21 -07:00
|
|
|
auth_method_id: '1234',
|
2021-11-04 15:06:42 -07:00
|
|
|
type: 'oidc',
|
2021-11-01 12:26:22 -07:00
|
|
|
attributes: {
|
|
|
|
|
filter: 'key=value',
|
|
|
|
|
},
|
2021-10-28 08:30:28 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|