Files
threshold-ui/addons/api/tests/unit/serializers/managed-groups-test.js
T
Carlos Alcaide Corvo 5df6b6de11 feat: 🎸 Refactor modeling
Remove OIDC as default value for fragment field filter. Applied default
value OIDC to type field. Accomodate tests for the changes. Add a
readOnly serializer test. Delete from fragment serializer not
serializing readOnly, because that is a case it will never reproduce on
such model.
2021-11-05 08:55:37 -07:00

128 lines
3.7 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | Managed groups', function (hooks) {
setupTest(hooks);
test('it serializes correctly on create with no filter provided', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-groups');
const record = store.createRecord('managed-groups', {
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',
type: 'OIDC',
attributes: {
filter: null,
},
});
});
test('it serializes correctly on create when filter provided', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-groups');
const record = store.createRecord('managed-groups', {
name: 'Group',
description: 'Description',
member_ids: ['1', '2'],
version: 1,
auth_method_id: '1234',
type: 'OIDC',
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',
type: 'OIDC',
attributes: {
filter: 'key=value',
},
});
});
test('it does not serialize readOnly attributes', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-groups');
const record = store.createRecord('managed-groups', {
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);
console.log(JSON.stringify(serializedRecord));
assert.deepEqual(serializedRecord, {
name: 'Group',
description: 'Description',
version: 1,
auth_method_id: '1234',
type: 'OIDC',
attributes: {
filter: null,
},
});
});
test('it serializes correctly on update', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-groups');
store.push({
data: {
id: '1',
type: 'managed-groups',
attributes: {
name: 'Group Test',
description: 'Description for the test',
member_ids: ['1', '2'],
version: 1,
auth_method_id: '1234',
type: 'OIDC',
attributes: {
filter: 'key=value',
},
},
},
});
const record = store.peekRecord('managed-groups', '1');
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
name: 'Group Test',
description: 'Description for the test',
version: 1,
auth_method_id: '1234',
type: 'OIDC',
attributes: {
filter: 'key=value',
},
});
});
});