feat: Normalize host_set_id in target host sets response
This commit is contained in:
3 files changed
+47
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import JSONSerializer from '@ember-data/serializer/json';
|
||||
|
||||
export default class FragmentHostSetSerializer extends JSONSerializer {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Renames `id` to `host_set_id` because fragments may not have IDs.
|
||||
* Otherwise normalizes as normal.
|
||||
* @param {ModelClass} typeClass
|
||||
* @param {object} resourceHash
|
||||
* @return {object}
|
||||
*/
|
||||
normalize(typeClass, { id: host_set_id, ...obj }) {
|
||||
return super.normalize(typeClass, { host_set_id, ...obj });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/fragment-host-set';
|
||||
@@ -0,0 +1,28 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import FragmentHostSet from 'api/models/fragment-host-set';
|
||||
|
||||
module('Unit | Serializer | fragment host set', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it normalizes `id` into `host_set_id`', function(assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('fragment-host-set');
|
||||
const normalized = serializer.normalize(FragmentHostSet, {
|
||||
host_set_id: '2',
|
||||
host_catalog_id: '1'
|
||||
});
|
||||
assert.deepEqual(normalized, {
|
||||
data: {
|
||||
attributes: {
|
||||
host_set_id: '2',
|
||||
host_catalog_id: '1'
|
||||
},
|
||||
id: null,
|
||||
relationships: {},
|
||||
type: 'fragment-host-set'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user