Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Fixed denormalization skipping of falsy valued ids used in Object schemas #345

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/schemas/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const denormalize = (schema, input, unvisit) => {

const object = { ...input };
Object.keys(schema).forEach((key) => {
if (object[key]) {
if (object[key] != null) {
object[key] = unvisit(object[key], schema[key]);
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/schemas/__tests__/Object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ describe(`${schema.Object.name} denormalization`, () => {
expect(denormalize({ user: 1 }, { user: userSchema, tacos: {} }, fromJS(entities))).toMatchSnapshot();
expect(denormalize(fromJS({ user: 1 }), { user: userSchema, tacos: {} }, fromJS(entities))).toMatchSnapshot();
});

test('denormalizes an object that contains a property representing a an object with an id of zero', () => {
const userSchema = new schema.Entity('user');
const object = new schema.Object({
user: userSchema
});
const entities = {
user: {
0: { id: 0, name: 'Chancho' }
}
};
expect(denormalize({ user: 0 }, object, entities)).toMatchSnapshot();
expect(denormalize({ user: 0 }, object, fromJS(entities))).toMatchSnapshot();
expect(denormalize(fromJS({ user: 0 }), object, fromJS(entities))).toMatchSnapshot();
});
});
27 changes: 27 additions & 0 deletions src/schemas/__tests__/__snapshots__/Object.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ Immutable.Map {
}
`;

exports[`ObjectSchema denormalization denormalizes an object that contains a property representing a an object with an id of zero 1`] = `
Object {
"user": Object {
"id": 0,
"name": "Chancho",
},
}
`;

exports[`ObjectSchema denormalization denormalizes an object that contains a property representing a an object with an id of zero 2`] = `
Object {
"user": Immutable.Map {
"id": 0,
"name": "Chancho",
},
}
`;

exports[`ObjectSchema denormalization denormalizes an object that contains a property representing a an object with an id of zero 3`] = `
Immutable.Map {
"user": Immutable.Map {
"id": 0,
"name": "Chancho",
},
}
`;

exports[`ObjectSchema denormalization denormalizes plain object shorthand 1`] = `
Object {
"user": Object {
Expand Down