Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Jul 16, 2023
1 parent 986150a commit 0fa54d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
29 changes: 11 additions & 18 deletions packages/next/src/data/server/__tests__/addHookData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,24 @@ describe('addHookData', () => {
isMainQuery: false,
},
];
expect(addHookData(hookStates, {})).toMatchObject({
expect(addHookData(hookStates, {})).toStrictEqual({
props: {
fallback: {
'first-key': {
result: {
yoast_head: null,
yoast_head_json: null,
id: 0,
},
queriedObject: {},
pageInfo: samplePageInfo,
},
'second-key': {
queriedObject: {},
pageInfo: samplePageInfo,
result: { ...appSettingsResult, 'theme.json': null },
},
},
seo: {
yoast_head: sampleResult.yoast_head,
yoast_head_json: sampleYoast,
},
themeJSON: { ...sampleThemeJson },
Expand All @@ -85,30 +88,20 @@ describe('addHookData', () => {
},
];

expect(addHookData(hookStates, {})).toMatchObject({
expect(addHookData(hookStates, {})).toStrictEqual({
props: {
fallback: {
'first-key': {
result: [
{
yoast_head: null,
yoast_head_json: null,
},
{
yoast_head: null,
yoast_head_json: null,
},
{
yoast_head: null,
yoast_head_json: null,
},
],
queriedObject: {},
result: [{ id: 0 }, { id: 0 }, { id: 0 }],
pageInfo: samplePageInfo,
},
},
seo: {
yoast_head: sampleResult.yoast_head,
yoast_head_json: sampleYoast,
},
themeJSON: {},
},
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/data/server/addHookData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function addHookData<P = { [key: string]: any }>(
seo = post.yoast_head;
}

delete cleanedUpPost.yoast_head_json;
delete cleanedUpPost.yoast_head;
}

return cleanedUpPost;
Expand All @@ -160,15 +160,15 @@ export function addHookData<P = { [key: string]: any }>(
if (!foundSeoJson) {
seo_json = { ...data.result.yoast_head_json };
}
data.result.yoast_head_json = null;
delete data.result.yoast_head_json;
}

if (data.result?.yoast_head) {
if (!foundSeo) {
seo = data.result.yoast_head;
}

data.result.yoast_head = null;
delete data.result.yoast_head;
}

if (data.result?.['theme.json']) {
Expand Down

0 comments on commit 0fa54d1

Please sign in to comment.