Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kitsu-core): deserialize meta only relationships #727

Merged
merged 2 commits into from
Aug 17, 2022

Conversation

pedep
Copy link
Contributor

@pedep pedep commented Aug 17, 2022

same as with links only:

it('deserialises relationships with links', () => {
expect.assertions(1)
expect(deserialise({
data: {
id: '1',
type: 'users',
relationships: {
followers: {
links: {
self: 'https://kitsu.example/users/1/relationships/followers',
related: 'https://kitsu.example/users/1/followers'
}
}
}
}
})).toEqual({
data: {
id: '1',
type: 'users',
followers: {
links: {
self: 'https://kitsu.example/users/1/relationships/followers',
related: 'https://kitsu.example/users/1/followers'
}
}
}
})
})

Section 5.2.4 of documentation states "A “relationship object” MUST contain at least one of the following: links, data or meta", so meta-only relationships should be just as valid as links only.

With this we PR support all cases.

The test-case for links, meta and data at the same time is handled indirectly by other specs, such as here:

it('Deserializes nested single circular resource', () => {
expect.assertions(1)
const input = JSON.parse(stringify(deserialise({
data: [
{
id: '1',
type: 'anime',
attributes: { name: 'A' },
relationships: {
user: {
data: {
id: '1',
type: 'users'
},
links: {
self: 'https://kitsu.example/user',
related: 'https://kitsu.example/user'
},
meta: {
hello: 'world'
}
}
}
},
{
id: '2',
type: 'anime',
attributes: { name: 'B' },
relationships: {
user: {
data: {
id: '1',
type: 'users'
}
}
}
}
],
included: [
{
id: '1',
type: 'users',
attributes: { name: 'B' },
relationships: {
favorite_anime: {
data: {
id: '1',
type: 'anime'
},
links: {
self: 'https://kitsu.example/favorite_anime',
related: 'https://kitsu.example/favorite_anime'
},
meta: {
test: '123123'
}
}
}
}
]
})))

@codeclimate
Copy link

codeclimate bot commented Aug 17, 2022

Code Climate has analyzed commit a71c9db and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (100% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

@wopian wopian merged commit 5b2c64c into wopian:master Aug 17, 2022
@pedep pedep deleted the fix(kitsu-core)/deserialize-meta-only branch August 17, 2022 12:54
wopian added a commit that referenced this pull request Aug 17, 2022
Backport of #727

Co-authored-by: pedep <pedep@users.noreply.github.com>
wopian added a commit that referenced this pull request Aug 17, 2022
Backport of #727

Co-authored-by: pedep <pedep@users.noreply.github.com>

Co-authored-by: pedep <pedep@users.noreply.github.com>
@wopian
Copy link
Owner

wopian commented Aug 17, 2022

Released as 9.1.29 and 10.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants