|
1 | 1 | import { Hono } from 'hono'
|
2 | 2 | import { setupServer } from 'msw/node'
|
3 |
| -import type { DiscordUser } from '../src/providers/discord' |
4 |
| -import { |
5 |
| - discordAuth, |
6 |
| - refreshToken as discordRefresh, |
7 |
| - revokeToken as discordRevoke, |
8 |
| -} from '../src/providers/discord' |
9 |
| -import { facebookAuth } from '../src/providers/facebook' |
10 |
| -import type { FacebookUser } from '../src/providers/facebook' |
11 |
| -import { githubAuth } from '../src/providers/github' |
12 |
| -import type { GitHubUser } from '../src/providers/github' |
13 |
| -import { googleAuth } from '../src/providers/google' |
14 |
| -import type { GoogleUser } from '../src/providers/google' |
15 |
| -import { linkedinAuth } from '../src/providers/linkedin' |
16 |
| -import type { LinkedInUser } from '../src/providers/linkedin' |
17 |
| -import type { TwitchUser } from '../src/providers/twitch' |
18 |
| -import { |
19 |
| - twitchAuth, |
20 |
| - refreshToken as twitchRefresh, |
21 |
| - revokeToken as twitchRevoke, |
22 |
| - validateToken as twitchValidate |
23 |
| -} from '../src/providers/twitch' |
24 |
| -import type { XUser } from '../src/providers/x' |
25 |
| -import { refreshToken, revokeToken, xAuth } from '../src/providers/x' |
26 |
| -import type { Token } from '../src/types' |
27 | 3 | import {
|
28 | 4 | discordCodeError,
|
29 | 5 | discordRefreshToken,
|
@@ -57,7 +33,31 @@ import {
|
57 | 33 | twitchUser,
|
58 | 34 | twitchValidateSuccess,
|
59 | 35 | twitchValidateError,
|
60 |
| -} from './handlers' |
| 36 | +} from '../mocks' |
| 37 | +import type { DiscordUser } from './providers/discord' |
| 38 | +import { |
| 39 | + discordAuth, |
| 40 | + refreshToken as discordRefresh, |
| 41 | + revokeToken as discordRevoke, |
| 42 | +} from './providers/discord' |
| 43 | +import { facebookAuth } from './providers/facebook' |
| 44 | +import type { FacebookUser } from './providers/facebook' |
| 45 | +import { githubAuth } from './providers/github' |
| 46 | +import type { GitHubUser } from './providers/github' |
| 47 | +import { googleAuth } from './providers/google' |
| 48 | +import type { GoogleUser } from './providers/google' |
| 49 | +import { linkedinAuth } from './providers/linkedin' |
| 50 | +import type { LinkedInUser } from './providers/linkedin' |
| 51 | +import type { TwitchUser } from './providers/twitch' |
| 52 | +import { |
| 53 | + twitchAuth, |
| 54 | + refreshToken as twitchRefresh, |
| 55 | + revokeToken as twitchRevoke, |
| 56 | + validateToken as twitchValidate, |
| 57 | +} from './providers/twitch' |
| 58 | +import type { XUser } from './providers/x' |
| 59 | +import { refreshToken, revokeToken, xAuth } from './providers/x' |
| 60 | +import type { Token } from './types' |
61 | 61 |
|
62 | 62 | const server = setupServer(...handlers)
|
63 | 63 | server.listen()
|
@@ -405,11 +405,7 @@ describe('OAuth Middleware', () => {
|
405 | 405 | })
|
406 | 406 | })
|
407 | 407 | app.get('/twitch/refresh', async (c) => {
|
408 |
| - const response = await twitchRefresh( |
409 |
| - client_id, |
410 |
| - client_secret, |
411 |
| - 'twitchr4nd0mr3fr3sht0k3n' |
412 |
| - ) |
| 408 | + const response = await twitchRefresh(client_id, client_secret, 'twitchr4nd0mr3fr3sht0k3n') |
413 | 409 | return c.json(response)
|
414 | 410 | })
|
415 | 411 | app.get('/twitch/refresh/error', async (c) => {
|
@@ -858,14 +854,14 @@ describe('OAuth Middleware', () => {
|
858 | 854 | })
|
859 | 855 |
|
860 | 856 | describe('twitchAuth middleware', () => {
|
861 |
| - it('Should work with custom state', async () => { |
862 |
| - const res = await app.request('/twitch-custom-state') |
863 |
| - expect(res).not.toBeNull() |
864 |
| - expect(res.status).toBe(302) |
865 |
| - const redirectLocation = res.headers.get('location')! |
866 |
| - const redirectUrl = new URL(redirectLocation) |
867 |
| - expect(redirectUrl.searchParams.get('state')).toBe('test-state') |
868 |
| - }) |
| 857 | + it('Should work with custom state', async () => { |
| 858 | + const res = await app.request('/twitch-custom-state') |
| 859 | + expect(res).not.toBeNull() |
| 860 | + expect(res.status).toBe(302) |
| 861 | + const redirectLocation = res.headers.get('location')! |
| 862 | + const redirectUrl = new URL(redirectLocation) |
| 863 | + expect(redirectUrl.searchParams.get('state')).toBe('test-state') |
| 864 | + }) |
869 | 865 | })
|
870 | 866 |
|
871 | 867 | describe('twitchAuth middleware', () => {
|
@@ -970,7 +966,7 @@ describe('OAuth Middleware', () => {
|
970 | 966 | const res = await twitchValidate('twitchr4nd0m4cc3sst0k3n')
|
971 | 967 | expect(res).toEqual(twitchValidateSuccess)
|
972 | 968 | })
|
973 |
| - |
| 969 | + |
974 | 970 | it('Should throw error for invalid token', async () => {
|
975 | 971 | const res = twitchValidate('invalid-token')
|
976 | 972 | await expect(res).rejects.toThrow(twitchValidateError.message)
|
|
0 commit comments