Skip to content

Commit

Permalink
removed attribute property need
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemengatto committed Nov 26, 2020
1 parent ae67805 commit a84cf13
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function parseJsonApiSimpleResourceData (data, included, useCache, options) {
return included.cached[data.type][data.id]
}

let attributes = data.attributes
let attributes = data.attributes || {}

if (options.changeCase) {
attributes = changeCase(attributes, options.changeCase)
Expand Down
38 changes: 38 additions & 0 deletions tests/deserialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,42 @@ describe('deserialize', () => {
}
])
})

it('Deserialize data without attributes', () => {
const serialized = {
data: [
{
type: 'users',
id: 1,
relationships: {
address: {
data: {
type: 'addr',
id: 1
}
}
}
}
],
included: [
{
type: 'addr',
id: 1,
attributes: {
street: 'Street 1'
}
}
]
}

expect(deserialize(serialized)).toEqual([
{
id: 1,
address: {
id: 1,
street: 'Street 1'
}
}
])
})
});

0 comments on commit a84cf13

Please sign in to comment.