spiceflow 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ import { test, describe, expect } from 'vitest'
2
+ import { Type } from '@sinclair/typebox'
3
+ import { Spiceflow } from './spiceflow'
4
+ import { req } from './utils'
5
+ import { z } from 'zod'
6
+
7
+ test('body is parsed as json', async () => {
8
+ let name = ''
9
+ const res = await new Spiceflow()
10
+ .state('id', '')
11
+
12
+ .post(
13
+ '/post',
14
+ (c) => {
15
+ name = c.body.name
16
+ // @ts-expect-error
17
+ c.body.nonExistingField
18
+ return {
19
+ name,
20
+ nameEcho: c.body.name,
21
+ // add: 3,
22
+ }
23
+ },
24
+ {
25
+ body: z.object({
26
+ name: z.string(),
27
+ }),
28
+ response: z.object({
29
+ name: z.string(),
30
+ nameEcho: z.string(),
31
+ }),
32
+ },
33
+ )
34
+ .post(
35
+ '/post2',
36
+ (c) => {
37
+ name = c.body.name
38
+ // @ts-expect-error
39
+ c.body.nonExistingField
40
+ return {
41
+ name,
42
+ nameEcho: c.body.name,
43
+ }
44
+ },
45
+ {
46
+ body: z.object({
47
+ name: z.string(),
48
+ }),
49
+ response: {
50
+ 200: z.object({
51
+ name: z.string(),
52
+ nameEcho: z.string(),
53
+ }),
54
+ 400: z.object({
55
+ errorMessage: z.string(),
56
+ }),
57
+ },
58
+ },
59
+ )
60
+ .handle(
61
+ req('/post', {
62
+ method: 'POST',
63
+ headers: {
64
+ 'content-type': 'application/json',
65
+ },
66
+ body: JSON.stringify({ name: 'John' }),
67
+ }),
68
+ )
69
+ expect(res.status).toBe(200)
70
+ expect(await res.json()).toEqual({ name: 'John', nameEcho: 'John' })
71
+ })