refactor: 💡 serialize scope_id by default

This commit is contained in:
Randall Morey committed 2020-09-10 18:32:17 -04:00
1 parent 974b557ae2
commit ab608c7544
21 files changed
+7 -266

No files matched your search

+5 -16
View File
@@ -8,18 +8,6 @@ import { copy } from 'ember-copy';
*/
export default class ApplicationSerializer extends RESTSerializer {
// =attributes
attrs = {
scope: { serialize: false }
};
/**
* Whether or not to serialize the scope ID into scope_id.
* @type {boolean}
*/
serializeScopeID = false;
// =methods
/**
@@ -81,10 +69,11 @@ export default class ApplicationSerializer extends RESTSerializer {
*/
serialize(snapshot) {
const serialized = super.serialize(...arguments);
if (this.serializeScopeID) {
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
if (scope_id) serialized.scope_id = scope_id;
}
// Delete `scope` field
delete serialized.scope;
// And serialize `scope_id`
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
if (scope_id) serialized.scope_id = scope_id;
return serialized;
}
@@ -1,13 +0,0 @@
import ApplicationSerializer from './application';
export default class AuthMethodSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
}
-8
View File
@@ -2,14 +2,6 @@ import ApplicationSerializer from './application';
export default class GroupSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
// =methods
/**
@@ -1,13 +0,0 @@
import ApplicationSerializer from './application';
export default class HostCatalogSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
}
-8
View File
@@ -2,14 +2,6 @@ import ApplicationSerializer from './application';
export default class HostSetSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
// =methods
/**
-13
View File
@@ -1,13 +0,0 @@
import ApplicationSerializer from './application';
export default class HostSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
}
-8
View File
@@ -3,14 +3,6 @@ import { get } from '@ember/object';
export default class RoleSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
// =methods
/**
-11
View File
@@ -1,11 +0,0 @@
import ApplicationSerializer from './application';
export default class ScopeSerializer extends ApplicationSerializer {
/**
* Serialize the scope ID into scope_id.
* @type {boolean}
*/
serializeScopeID = true;
}
-8
View File
@@ -2,14 +2,6 @@ import ApplicationSerializer from './application';
export default class TargetSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
// =methods
/**
-13
View File
@@ -1,13 +0,0 @@
import ApplicationSerializer from './application';
export default class UserSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
}
@@ -1 +0,0 @@
export { default } from 'api/serializers/auth-method';
@@ -1 +0,0 @@
export { default } from 'api/serializers/host-catalog';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/serializers/host';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/serializers/scope';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/serializers/user';
@@ -30,11 +30,9 @@ module('Unit | Serializer | application', function (hooks) {
});
});
test('it does not serialize scope_id when serializeScopeID is false', function (assert) {
assert.expect(2);
test('it serializes scope_id when scope is set', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('user');
serializer.serializeScopeID = false;
const record = store.createRecord('user', {
name: 'User',
description: 'Description',
@@ -44,28 +42,6 @@ module('Unit | Serializer | application', function (hooks) {
}
});
const serializedRecord = record.serialize();
assert.equal(serializer.serializeScopeID, false);
assert.deepEqual(serializedRecord, {
name: 'User',
description: 'Description'
});
});
test('it does serialize scope_id when serializeScopeID is true', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('user');
serializer.serializeScopeID = true;
const record = store.createRecord('user', {
name: 'User',
description: 'Description',
scope: {
scope_id: 'global',
type: 'global'
}
});
const serializedRecord = record.serialize();
assert.equal(serializer.serializeScopeID, true);
assert.deepEqual(serializedRecord, {
name: 'User',
description: 'Description',
@@ -1,24 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | auth method', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('auth-method');
assert.ok(serializer);
});
test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('auth-method', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});
@@ -1,23 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | host catalog', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('host-catalog');
assert.ok(serializer);
});
test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('host-catalog', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});
@@ -1,23 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | host', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('host');
assert.ok(serializer);
});
test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('host', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});
@@ -1,31 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | scope', function(hooks) {
setupTest(hooks);
test('it serializes scope_id into payloads', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('scope');
serializer.serializeScopeID = true;
const record = store.createRecord('scope', {
name: 'My Scope',
description: 'Foo',
type: 'org',
scope: {
scope_id: 'global',
type: 'global'
}
});
const serializedRecord = record.serialize();
assert.equal(serializer.serializeScopeID, true);
assert.deepEqual(serializedRecord, {
name: 'My Scope',
description: 'Foo',
type: 'org',
scope_id: 'global'
});
});
});
@@ -1,23 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | user', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('user');
assert.ok(serializer);
});
test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('user', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});