-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsseContractBuilders.metadata.spec.ts
More file actions
173 lines (154 loc) · 5.13 KB
/
sseContractBuilders.metadata.spec.ts
File metadata and controls
173 lines (154 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { describe, expect, expectTypeOf, it } from 'vitest'
import { z } from 'zod/v4'
import { buildSseContract } from './sseContractBuilders.ts'
const SCHEMA = z.object({})
const EVENTS = { data: z.object({ value: z.string() }) }
type Metadata = {
myTestProp?: string[]
mySecondTestProp?: number
}
declare module '../apiContracts.ts' {
interface CommonRouteDefinitionMetadata extends Metadata {}
}
describe('buildSseContract metadata augmentation', () => {
describe('SSE GET route', () => {
it('should respect metadata type and reflect it on contract', () => {
const contract = buildSseContract({
method: 'get',
pathResolver: () => '/',
serverSentEventSchemas: EVENTS,
metadata: {
myTestProp: ['test'],
mySecondTestProp: 1,
extra: 'extra field',
},
})
expectTypeOf(contract.metadata).toMatchTypeOf<Metadata | undefined>()
expect(contract.metadata).toEqual({
myTestProp: ['test'],
mySecondTestProp: 1,
extra: 'extra field',
})
})
it('should reflect description, summary, and tags on contract', () => {
const contract = buildSseContract({
method: 'get',
pathResolver: () => '/',
serverSentEventSchemas: EVENTS,
description: 'Stream events',
summary: 'Event stream',
tags: ['streaming', 'sse'],
})
expect(contract.description).toBe('Stream events')
expect(contract.summary).toBe('Event stream')
expect(contract.tags).toEqual(['streaming', 'sse'])
})
})
describe('SSE POST route', () => {
it('should respect metadata type and reflect it on contract', () => {
const contract = buildSseContract({
method: 'post',
pathResolver: () => '/',
requestBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
metadata: {
myTestProp: ['test2'],
mySecondTestProp: 2,
extra: 'extra field2',
},
})
expectTypeOf(contract.metadata).toMatchTypeOf<Metadata | undefined>()
expect(contract.metadata).toEqual({
myTestProp: ['test2'],
mySecondTestProp: 2,
extra: 'extra field2',
})
})
it('should reflect description, summary, and tags on contract', () => {
const contract = buildSseContract({
method: 'post',
pathResolver: () => '/',
requestBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
description: 'Stream with body',
summary: 'Body stream',
tags: ['streaming'],
})
expect(contract.description).toBe('Stream with body')
expect(contract.summary).toBe('Body stream')
expect(contract.tags).toEqual(['streaming'])
})
})
describe('Dual-mode GET route', () => {
it('should respect metadata type and reflect it on contract', () => {
const contract = buildSseContract({
method: 'get',
pathResolver: () => '/',
successResponseBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
metadata: {
myTestProp: ['test3'],
mySecondTestProp: 3,
extra: 'extra field3',
},
})
expectTypeOf(contract.metadata).toMatchTypeOf<Metadata | undefined>()
expect(contract.metadata).toEqual({
myTestProp: ['test3'],
mySecondTestProp: 3,
extra: 'extra field3',
})
})
it('should reflect description, summary, and tags on contract', () => {
const contract = buildSseContract({
method: 'get',
pathResolver: () => '/',
successResponseBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
description: 'Dual-mode GET',
summary: 'GET dual',
tags: ['dual-mode', 'sse'],
})
expect(contract.description).toBe('Dual-mode GET')
expect(contract.summary).toBe('GET dual')
expect(contract.tags).toEqual(['dual-mode', 'sse'])
})
})
describe('Dual-mode POST route', () => {
it('should respect metadata type and reflect it on contract', () => {
const contract = buildSseContract({
method: 'post',
pathResolver: () => '/',
requestBodySchema: SCHEMA,
successResponseBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
metadata: {
myTestProp: ['test4'],
mySecondTestProp: 4,
extra: 'extra field4',
},
})
expectTypeOf(contract.metadata).toMatchTypeOf<Metadata | undefined>()
expect(contract.metadata).toEqual({
myTestProp: ['test4'],
mySecondTestProp: 4,
extra: 'extra field4',
})
})
it('should reflect description, summary, and tags on contract', () => {
const contract = buildSseContract({
method: 'post',
pathResolver: () => '/',
requestBodySchema: SCHEMA,
successResponseBodySchema: SCHEMA,
serverSentEventSchemas: EVENTS,
description: 'Dual-mode POST',
summary: 'POST dual',
tags: ['dual-mode'],
})
expect(contract.description).toBe('Dual-mode POST')
expect(contract.summary).toBe('POST dual')
expect(contract.tags).toEqual(['dual-mode'])
})
})
})