Skip to content

Commit

Permalink
Use MSW with parameters instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed May 15, 2024
1 parent acf38ae commit be0769e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions app/note/[id]/page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit be0769e

Please sign in to comment.