-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
}); | ||
}); |
File renamed without changes.