test: Refactor 'nestedResource' to 'serializeScopeID'
This commit is contained in:
6 files changed
+28
-14
No files matched your search
@@ -7,9 +7,9 @@ export default class AccountModel extends GeneratedAccountModel {
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* Account resource is nested within auth methods.
|
||||
* @type {boolean}
|
||||
*/
|
||||
nestedResource = true;
|
||||
serializeScopeID = false;
|
||||
|
||||
// =attributes
|
||||
|
||||
|
||||
@@ -26,6 +26,14 @@ import { get } from '@ember/object';
|
||||
* 2) Or as an ID: `record.scopeID`.
|
||||
*/
|
||||
export default class BaseModel extends Model {
|
||||
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
// =relationships
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,9 +6,9 @@ export default class HostSetModel extends GeneratedHostSetModel {
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* Account resource is nested within auth methods.
|
||||
* @type {boolean}
|
||||
*/
|
||||
nestedResource = true;
|
||||
serializeScopeID = false;
|
||||
|
||||
// =attributes
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ export default class HostModel extends GeneratedHostModel {
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* Account resource is nested within auth methods.
|
||||
* @type {boolean}
|
||||
*/
|
||||
nestedResource = true;
|
||||
serializeScopeID = false;
|
||||
|
||||
/**
|
||||
* Attributes of this resource, if any, represented as a JSON fragment.
|
||||
|
||||
@@ -70,8 +70,8 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
const serialized = super.serialize(...arguments);
|
||||
// Delete `scope` field
|
||||
delete serialized.scope;
|
||||
// And serialize `scope_id` when not a nested resource
|
||||
if(!snapshot?.record?.nestedResource) {
|
||||
// And serialize `scope_id`
|
||||
if(snapshot?.record?.serializeScopeID) {
|
||||
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
|
||||
if (scope_id) serialized.scope_id = scope_id;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes scope_id when scope is set', function (assert) {
|
||||
test('it serializes scope_id', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('user', {
|
||||
@@ -49,19 +49,25 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test('it does not serialize scope_id when resource is nested', function (assert) {
|
||||
test('it does not serialize scope_id when serializeScopeID is false', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('account', {
|
||||
name: 'Account',
|
||||
const serializer = store.serializerFor('user');
|
||||
const record = store.createRecord('user', {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
scope: {
|
||||
scope_id: 'global',
|
||||
type: 'global',
|
||||
},
|
||||
});
|
||||
const serializedRecord = record.serialize();
|
||||
assert.notOk(serializedRecord.scope_id);
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.record.serializeScopeID = false;
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
assert.deepEqual(serializedRecord, {
|
||||
name: 'User',
|
||||
description: 'Description'
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes non-nullish version fields', function (assert) {
|
||||
|
||||
Reference in new issue
Block a user