refactor: Refactor seralizeScopeID from models to serializers

This commit is contained in:
Susmitha Girumala committed 2020-09-21 18:23:32 -04:00
1 parent 1a565f9097
commit 0a1eafe55e
11 files changed
+63 -30

No files matched your search

-7
View File
@@ -4,13 +4,6 @@ import { computed } from '@ember/object';
export default class AccountModel extends GeneratedAccountModel {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
// =attributes
/**
-7
View File
@@ -27,13 +27,6 @@ import { get } from '@ember/object';
*/
export default class BaseModel extends Model {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = true;
// =relationships
/**
-7
View File
@@ -3,13 +3,6 @@ import { fragmentArray } from 'ember-data-model-fragments/attributes';
export default class HostSetModel extends GeneratedHostSetModel {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
// =attributes
/**
+1 -7
View File
@@ -3,16 +3,10 @@ import { fragment } from 'ember-data-model-fragments/attributes';
export default class HostModel extends GeneratedHostModel {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
/**
* Attributes of this resource, if any, represented as a JSON fragment.
* @type {FragmentHostAttributesModel}
*/
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
}
+8
View File
@@ -1,6 +1,14 @@
import ApplicationSerializer from './application';
export default class AccountSerializer extends ApplicationSerializer {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
// =methods
/**
+9 -1
View File
@@ -7,6 +7,14 @@ import { copy } from 'ember-copy';
* Manages serialization/normalization of data to/from the API.
*/
export default class ApplicationSerializer extends RESTSerializer {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = true;
// =methods
/**
@@ -71,7 +79,7 @@ export default class ApplicationSerializer extends RESTSerializer {
// Delete `scope` field
delete serialized.scope;
// And serialize `scope_id`
if(snapshot?.record?.serializeScopeID) {
if(this.serializeScopeID) {
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
if (scope_id) serialized.scope_id = scope_id;
}
+8
View File
@@ -1,6 +1,14 @@
import ApplicationSerializer from './application';
export default class HostSetSerializer extends ApplicationSerializer {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
// =methods
/**
+12
View File
@@ -0,0 +1,12 @@
import ApplicationSerializer from './application';
export default class HostSerializer extends ApplicationSerializer {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
}
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/serializers/host';
@@ -62,7 +62,7 @@ module('Unit | Serializer | application', function (hooks) {
},
});
const snapshot = record._createSnapshot();
snapshot.record.serializeScopeID = false;
serializer.serializeScopeID = false;
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
name: 'User',
@@ -0,0 +1,23 @@
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);
});
});