Skip to content

Commit

Permalink
Add tests for cache-control setting
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 committed Aug 19, 2024
1 parent 6556e9d commit f53512c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { GetServerSidePropsContext } from 'next';
import handleAvRoute from './handleAvRoute';

const mockGetServerSidePropsContext = {
req: {
cookies: {},
headers: {},
},
res: {
setHeader: jest.fn(),
},
query: {
service: 'news',
},
} as unknown as GetServerSidePropsContext;

describe('Handle AV Route', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should set the cache control header correctly for a Syndication route', async () => {
const { req, res, query } = mockGetServerSidePropsContext;

await handleAvRoute({
req,
res,
resolvedUrl: '/news/av-embeds/123',
query,
});

expect(mockGetServerSidePropsContext.res.setHeader).toHaveBeenCalledWith(
'Cache-Control',
'private, stale-if-error=90, stale-while-revalidate=30, max-age=0, must-revalidate',
);
});

it('should set the cache control header correctly for a non-Syndication route', async () => {
const { req, res, query } = mockGetServerSidePropsContext;

await handleAvRoute({
req,
res,
resolvedUrl: '/ws/av-embeds/123',
query,
});

expect(mockGetServerSidePropsContext.res.setHeader).toHaveBeenCalledWith(
'Cache-Control',
'public, stale-if-error=90, stale-while-revalidate=30, max-age=30',
);
});
});

0 comments on commit f53512c

Please sign in to comment.