Skip to content

Commit 4a0a14e

Browse files
Adding specs
1 parent c8db2d4 commit 4a0a14e

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

__tests__/json-api-response-converter.spec.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,92 @@ describe('JsonApiResponseConverter converts', () => {
434434
}
435435
])
436436
})
437+
438+
test('response has nested included relationship', () => {
439+
const response = {
440+
data: {
441+
id: '1',
442+
type: 'posts',
443+
attributes: {
444+
title: 'This project is awesome'
445+
},
446+
relationships: {
447+
author: {
448+
data: { id: '1', type: 'author' }
449+
},
450+
451+
comments: {
452+
data: [
453+
{ id: '1', type: 'comment' },
454+
{ id: '2', type: 'comment' }
455+
]
456+
}
457+
}
458+
},
459+
included: [
460+
{
461+
id: '1',
462+
type: 'author',
463+
attributes: {
464+
name: 'Anakin'
465+
}
466+
},
467+
{
468+
id: '1',
469+
type: 'comment',
470+
attributes: {
471+
body: 'First!'
472+
}
473+
},
474+
{
475+
id: '2',
476+
type: 'comment',
477+
attributes: {
478+
body: 'Second!'
479+
},
480+
relationships: {
481+
comments: {
482+
data: [
483+
{ id: '3', type: 'comment' }
484+
]
485+
}
486+
}
487+
},
488+
{
489+
id: '3',
490+
type: 'comment',
491+
attributes: {
492+
body: 'Third!'
493+
}
494+
}
495+
]
496+
}
497+
498+
expect(new JsonApiResponseConverter(response).formattedResponse).toEqual(
499+
{
500+
id: 1,
501+
title: 'This project is awesome',
502+
author: {
503+
id: 1,
504+
name: 'Anakin'
505+
},
506+
comments: [
507+
{
508+
id: 1,
509+
body: 'First!'
510+
},
511+
{
512+
id: 2,
513+
body: 'Second!',
514+
comments: [
515+
{
516+
id: 3,
517+
body: 'Third!'
518+
}
519+
]
520+
}
521+
]
522+
}
523+
)
524+
})
437525
})

0 commit comments

Comments
 (0)