Skip to content

Commit

Permalink
test: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Jun 28, 2024
1 parent 3006585 commit 46971cb
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/__tests__/queryPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('queryPosts', () => {
expect(data.post.slug).toBe('modi-qui-dignissimos-sed-assumenda-sint-iusto');
});

it.skip('issues not found', async () => {
it('issues not found', async () => {
await expect(
queryPost({
routeParams: {
Expand Down
39 changes: 39 additions & 0 deletions packages/next/src/rsc/data/queries/__tests__/queryPosts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { setHeadstartWPConfig } from '@headstartwp/core';
import { queryPosts } from '../queryPosts';

describe('queryPosts', () => {
beforeAll(() => {
setHeadstartWPConfig({
useWordPressPlugin: true,
});
});

afterAll(() => {
setHeadstartWPConfig({
useWordPressPlugin: false,
});
});

it('fetches posts', async () => {
const { data } = await queryPosts({
params: {
Expand All @@ -10,4 +23,30 @@ describe('queryPosts', () => {

expect(data.posts).toHaveLength(2);
});

it('issues not found', async () => {
await expect(
queryPosts({
routeParams: {
path: ['category', 'not-found-category'],
},
}),
).rejects.toThrow();
});

it('does not issue not found if throwIfNotFound is false', async () => {
const { data } = await queryPosts({
routeParams: {
path: ['not-found-category'],
},
params: {
taxonomy: 'category',
},
options: {
throwIfNotFound: false,
},
});

expect(data.posts).toHaveLength(0);
});
});
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function queryAppSettings<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryAuthorArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function queryAuthorArchive<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function queryPost<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryPostOrPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function queryPostOrPosts<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function queryPosts<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/querySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function querySearch<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/queries/queryTerms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function queryTerms<
return result;
} catch (error) {
if (error instanceof Error) {
handleFetchError(error, config, query.path);
await handleFetchError(error, config, query.path);
}
throw error;
}
Expand Down
5 changes: 0 additions & 5 deletions projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const Single = async ({ params }: HeadstartWPRoute) => {
params: {
matchCurrentPath: false,
},
options: {
headers: {
cache: 'no-store',
},
},
});

return (
Expand Down
13 changes: 13 additions & 0 deletions projects/wp-nextjs-app/src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from 'next/link';

const NotFound = () => {
return (
<div>
<h2>Not Found</h2>
<p>Could not find requested resource</p>
<Link href="/">Return Home</Link>
</div>
);
};

export default NotFound;

0 comments on commit 46971cb

Please sign in to comment.