Refactor model

This commit is contained in:
Carlos Alcaide Corvo committed 2021-11-05 08:55:37 -07:00
1 parent 322828ccc4
commit 360bf0ffdd
5 files changed
+31 -135

No files matched your search

@@ -4,7 +4,6 @@ import { setupTest } from 'ember-qunit';
module('Unit | Model | managed groups', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('managed-groups', {});
@@ -4,10 +4,8 @@ import { setupTest } from 'ember-qunit';
module('Unit | Serializer | Managed groups', function (hooks) {
setupTest(hooks);
test('it serializes managed groups normally, without members', function (assert) {
test('it serializes correctly on create', function (assert) {
assert.expect(1);
// TODO: move store declaration at module level. Before doing so, to make sure it works, generate one out, one in and deep compare.
// TODO: if moving store out works, move serializer too.
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-groups');
const record = store.createRecord('managed-groups', {
@@ -24,33 +22,41 @@ module('Unit | Serializer | Managed groups', function (hooks) {
assert.deepEqual(serializedRecord, {
name: 'Group',
description: 'Description',
member_ids: ['1', '2'],
version: 1,
auth_method_id: '1234',
type: '80',
});
});
test('it seralizes only members associated with this group and version when a `memberIDs` array is provided', function (assert) {
test('it serializes correctly on update', 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',
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: '80',
},
},
});
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',
member_ids: ['1', '2'],
version: 1,
auth_method_id: '1234',
type: '80',
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
memberIDs: ['4', '5'],
};
const serializedRecord = serializer.serialize(snapshot);
console.log(JSON.stringify(serializedRecord));
assert.deepEqual(serializedRecord, {
member_ids: ['4', '5'],
version: 1,
});
});
});