Skip to content

Commit be0769e

Browse files
committed
Use MSW with parameters instead
1 parent acf38ae commit be0769e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

app/note/[id]/page.stories.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,30 @@ export const LoggedIn: Story = {
5454
export const NotLoggedIn: Story = {}
5555

5656
export const LoginShouldGetOAuthTokenAndSetCookie: Story = {
57+
parameters: {
58+
msw: {
59+
// Mock out OAUTH
60+
handlers: [
61+
http.post(
62+
'https://github.com/login/oauth/access_token',
63+
async ({ request }) => {
64+
let json = (await request.json()) as any
65+
return Response.json({ access_token: json.code })
66+
},
67+
),
68+
http.get('https://api.github.com/user', async ({ request }) =>
69+
Response.json({
70+
login: request.headers.get('Authorization')?.replace('token ', ''),
71+
}),
72+
),
73+
],
74+
},
75+
},
5776
beforeEach() {
5877
// Point the login implementation to the endpoint github would have redirected too.
5978
login.mockImplementation(async () => {
6079
return await auth.GET(new Request('/auth?code=storybookjs'))
6180
})
62-
63-
// Mock out OAUTH
64-
getWorker().use(
65-
http.post(
66-
'https://github.com/login/oauth/access_token',
67-
async ({ request }) => {
68-
let json = (await request.json()) as any
69-
return Response.json({ access_token: json.code })
70-
},
71-
),
72-
http.get('https://api.github.com/user', async ({ request }) =>
73-
Response.json({
74-
login: request.headers.get('Authorization')?.replace('token ', ''),
75-
}),
76-
),
77-
)
7881
},
7982
play: async ({ canvasElement }) => {
8083
console.log(db.$getInternalState())

0 commit comments

Comments
 (0)