Skip to content

Commit d050514

Browse files
committed
test(@sirutils/wizard): middleware
1 parent baac022 commit d050514

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

packages/wizard/test/app.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
import './handler'
2+
import './middlewares/auth'
23
import './services/users'
34
import './services/mails'
4-
import './wizard'
5+
import { wizard } from './wizard'
56

6-
// import fs from 'node:fs'
7-
// import { logger } from '../src/internal/logger'
8-
// import { wizard } from './wizard'
9-
10-
// const result = await wizard.api.call(
11-
// 'users@0.1.1#create',
12-
// {
13-
// name: 'alice',
14-
// },
15-
// {
16-
// stream: [fs.createReadStream('.env'), fs.createReadStream('tsconfig.json')],
17-
// }
18-
// )
19-
20-
// logger.log(result)
7+
const result = await wizard.api.call('users@0.1.1#signOut', {}, {})
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { wizard } from '../wizard'
2+
3+
export const auth = wizard.api.createMiddleware(
4+
{
5+
name: 'auth',
6+
share: ['token'],
7+
},
8+
(ctx, next) => {
9+
ctx.share.token = 'qwerty1234567890'
10+
return next
11+
}
12+
)
13+
14+
declare global {
15+
// biome-ignore lint/style/noNamespace: <explanatiion>
16+
namespace Sirutils {
17+
// biome-ignore lint/style/noNamespace: <explanatiion>
18+
namespace Wizard {
19+
interface ContextShare {
20+
token: string
21+
}
22+
}
23+
24+
interface WizardMiddlewares {
25+
auth: typeof auth
26+
}
27+
}
28+
}

packages/wizard/test/services/users.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@ const usersService = await wizard.api.service({
66
description: 'users api',
77

88
actions: {
9-
create: wizard.api.createAction(
9+
signOut: wizard.api.createAction(
1010
{
11-
body: {
12-
name: 'string',
13-
},
14-
rest: true,
15-
stream: true,
16-
multipart: true,
11+
middlewares: ['auth'],
1712
},
1813
ctx => {
19-
if (ctx.streams) {
20-
// biome-ignore lint/suspicious/noConsole: <explanation>
21-
console.log(ctx.streams)
22-
}
14+
// biome-ignore lint/suspicious/noConsole: <explanation>
15+
console.log(ctx.share?.token)
2316

2417
return 'sa' as const
2518
}

0 commit comments

Comments
 (0)