From be0769e49bb64c87402126b247a87ff922f1c002 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 15 May 2024 11:04:15 +0200 Subject: [PATCH] Use MSW with parameters instead --- app/note/[id]/page.stories.tsx | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/note/[id]/page.stories.tsx b/app/note/[id]/page.stories.tsx index 0c26754..f322670 100644 --- a/app/note/[id]/page.stories.tsx +++ b/app/note/[id]/page.stories.tsx @@ -54,27 +54,30 @@ export const LoggedIn: Story = { export const NotLoggedIn: Story = {} export const LoginShouldGetOAuthTokenAndSetCookie: Story = { + parameters: { + msw: { + // Mock out OAUTH + handlers: [ + http.post( + 'https://github.com/login/oauth/access_token', + async ({ request }) => { + let json = (await request.json()) as any + return Response.json({ access_token: json.code }) + }, + ), + http.get('https://api.github.com/user', async ({ request }) => + Response.json({ + login: request.headers.get('Authorization')?.replace('token ', ''), + }), + ), + ], + }, + }, beforeEach() { // Point the login implementation to the endpoint github would have redirected too. login.mockImplementation(async () => { return await auth.GET(new Request('/auth?code=storybookjs')) }) - - // Mock out OAUTH - getWorker().use( - http.post( - 'https://github.com/login/oauth/access_token', - async ({ request }) => { - let json = (await request.json()) as any - return Response.json({ access_token: json.code }) - }, - ), - http.get('https://api.github.com/user', async ({ request }) => - Response.json({ - login: request.headers.get('Authorization')?.replace('token ', ''), - }), - ), - ) }, play: async ({ canvasElement }) => { console.log(db.$getInternalState())