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

test(unit): circular references in multi value fields #11

Merged
merged 1 commit into from
Jan 11, 2018
Merged
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
62 changes: 62 additions & 0 deletions test/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,68 @@ describe('Resolve a', function () {
equal(resolved[0].fields.linkfield.fields.linkfield.fields.linkfield.sys.id, 'two', 'sub sub link id');
});

it('response with links having circular references in multi value fields', function () {
const response = {
items: [
{
sys: { type: 'Entry', locale: 'en-US', id: 'A' },
fields: {
linkfield: [
{ sys: { type: 'Link', linkType: 'Entry', id: 'X' } },
{ sys: { type: 'Link', linkType: 'Entry', id: 'Y' } },
{ sys: { type: 'Link', linkType: 'Entry', id: 'Z' } }
]
}
}
],
includes: {
Entry: [
{
sys: { type: 'Entry', locale: 'en-US', id: 'X' },
fields: {
linkfield: [
{ sys: { type: 'Link', linkType: 'Entry', id: 'A' } }
]
}
},
{
sys: { type: 'Entry', locale: 'en-US', id: 'Y' },
fields: {
linkfield: [
{ sys: { type: 'Link', linkType: 'Entry', id: 'X' } }
]
}
},
{
sys: { type: 'Entry', locale: 'en-US', id: 'Z' },
fields: {
linkfield: [
{ sys: { type: 'Link', linkType: 'Entry', id: 'Y' } }
]
}
}
]
}
};

const resolved = resolveResponse(response);

equal(resolved[0].fields.linkfield[0].sys.type, 'Entry', 'first link type');
equal(resolved[0].fields.linkfield[0].sys.id, 'X', 'first link id');
equal(resolved[0].fields.linkfield[0].fields.linkfield[0].sys.type, 'Entry', 'sub link type');
equal(resolved[0].fields.linkfield[0].fields.linkfield[0].sys.id, 'A', 'sub link id');

equal(resolved[0].fields.linkfield[1].sys.type, 'Entry', 'first link type');
equal(resolved[0].fields.linkfield[1].sys.id, 'Y', 'first link id');
equal(resolved[0].fields.linkfield[1].fields.linkfield[0].sys.type, 'Entry', 'sub link type');
equal(resolved[0].fields.linkfield[1].fields.linkfield[0].sys.id, 'X', 'sub link id');

equal(resolved[0].fields.linkfield[2].sys.type, 'Entry', 'first link type');
equal(resolved[0].fields.linkfield[2].sys.id, 'Z', 'first link id');
equal(resolved[0].fields.linkfield[2].fields.linkfield[0].sys.type, 'Entry', 'sub link type');
equal(resolved[0].fields.linkfield[2].fields.linkfield[0].sys.id, 'Y', 'sub link id');
});

it('response with links should resolve complex references between items and includes', function () {
const items = [
{
Expand Down