@thymian/core-testing 0.0.0-PLACEHOLDER
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.
- package/README.md +327 -0
- package/dist/factories/http-request.factory.d.ts +40 -0
- package/dist/factories/http-request.factory.d.ts.map +1 -0
- package/dist/factories/http-request.factory.js +85 -0
- package/dist/factories/http-request.factory.js.map +1 -0
- package/dist/factories/http-response.factory.d.ts +51 -0
- package/dist/factories/http-response.factory.d.ts.map +1 -0
- package/dist/factories/http-response.factory.js +110 -0
- package/dist/factories/http-response.factory.js.map +1 -0
- package/dist/factories/parameter.factory.d.ts +28 -0
- package/dist/factories/parameter.factory.d.ts.map +1 -0
- package/dist/factories/parameter.factory.js +48 -0
- package/dist/factories/parameter.factory.js.map +1 -0
- package/dist/factories/schema.factory.d.ts +45 -0
- package/dist/factories/schema.factory.d.ts.map +1 -0
- package/dist/factories/schema.factory.js +81 -0
- package/dist/factories/schema.factory.js.map +1 -0
- package/dist/factories/thymian-format.factory.d.ts +46 -0
- package/dist/factories/thymian-format.factory.d.ts.map +1 -0
- package/dist/factories/thymian-format.factory.js +65 -0
- package/dist/factories/thymian-format.factory.js.map +1 -0
- package/dist/http-testing-utils.d.ts +5 -0
- package/dist/http-testing-utils.d.ts.map +1 -0
- package/dist/http-testing-utils.js +27 -0
- package/dist/http-testing-utils.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/mocks/emitter.mock.d.ts +71 -0
- package/dist/mocks/emitter.mock.d.ts.map +1 -0
- package/dist/mocks/emitter.mock.js +101 -0
- package/dist/mocks/emitter.mock.js.map +1 -0
- package/dist/mocks/logger.mock.d.ts +29 -0
- package/dist/mocks/logger.mock.d.ts.map +1 -0
- package/dist/mocks/logger.mock.js +61 -0
- package/dist/mocks/logger.mock.js.map +1 -0
- package/dist/mocks/plugin.mock.d.ts +85 -0
- package/dist/mocks/plugin.mock.d.ts.map +1 -0
- package/dist/mocks/plugin.mock.js +102 -0
- package/dist/mocks/plugin.mock.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<!-- HEADER:START - Do not remove or modify this section -->
|
|
2
|
+
<div align="center">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/thymianofficial/thymian/main/astro-docs/src/assets/logo.svg" alt="Thymian Logo" width="200"/>
|
|
4
|
+
|
|
5
|
+
# Thymian
|
|
6
|
+
|
|
7
|
+
**Add resilience and HTTP conformance to your API development workflow**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/thymianofficial/thymian/blob/main/LICENSE)
|
|
10
|
+
[](https://github.com/thymianofficial/thymian/actions/workflows/ci.yaml)
|
|
11
|
+
[](https://thymian.dev)
|
|
12
|
+
[](https://discord.gg/TRSwCxbz9f)
|
|
13
|
+
[](https://www.reddit.com/r/ThymianOfficial/)
|
|
14
|
+
[](https://x.com/thymiandev)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
<!-- HEADER:END -->
|
|
18
|
+
|
|
19
|
+
## @thymian/core-testing
|
|
20
|
+
|
|
21
|
+
`@thymian/core-testing` provides reusable testing utilities that make it easy to write tests for Thymian plugins and components. It includes:
|
|
22
|
+
|
|
23
|
+
- **Factories** for creating test data with sensible defaults
|
|
24
|
+
- **Mocks** for all major Thymian interfaces
|
|
25
|
+
- **Type-safe** utilities that match the `@thymian/core` types exactly
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install --save-dev @thymian/core-testing
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { createHttpRequest, createHttpResponse, createMockLogger, createMockEmitter, createMockPlugin } from '@thymian/core-testing';
|
|
37
|
+
|
|
38
|
+
// Create test data with sensible defaults
|
|
39
|
+
const request = createGetRequest({ path: '/users' });
|
|
40
|
+
const response = createOkResponse();
|
|
41
|
+
|
|
42
|
+
// Create test doubles
|
|
43
|
+
const logger = createMockLogger();
|
|
44
|
+
const emitter = createMockEmitter();
|
|
45
|
+
|
|
46
|
+
// Test your plugin
|
|
47
|
+
await myPlugin(emitter, logger, { cwd: '/test' });
|
|
48
|
+
|
|
49
|
+
// Assert on calls
|
|
50
|
+
expect(logger.info).toHaveBeenCalled();
|
|
51
|
+
expect(emitter.emit).toHaveBeenCalledWith('core.register', expect.any(Object));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### API Reference
|
|
55
|
+
|
|
56
|
+
#### Factories
|
|
57
|
+
|
|
58
|
+
##### Schema Factories
|
|
59
|
+
|
|
60
|
+
Create ThymianSchema objects with sensible defaults:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { createThymianSchema, createStringSchema, createNumberSchema, createIntegerSchema, createBooleanSchema, createObjectSchema, createArraySchema } from '@thymian/core-testing';
|
|
64
|
+
|
|
65
|
+
// Basic schemas
|
|
66
|
+
const stringSchema = createStringSchema({ minLength: 5, maxLength: 50 });
|
|
67
|
+
const numberSchema = createNumberSchema({ minimum: 0, maximum: 100 });
|
|
68
|
+
const integerSchema = createIntegerSchema();
|
|
69
|
+
const booleanSchema = createBooleanSchema();
|
|
70
|
+
|
|
71
|
+
// Complex schemas
|
|
72
|
+
const objectSchema = createObjectSchema({
|
|
73
|
+
name: createStringSchema(),
|
|
74
|
+
age: createIntegerSchema(),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const arraySchema = createArraySchema(createStringSchema());
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
##### Parameter Factories
|
|
81
|
+
|
|
82
|
+
Create Parameter objects:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { createParameter, createRequiredParameter, createOptionalParameter } from '@thymian/core-testing';
|
|
86
|
+
|
|
87
|
+
const param = createParameter({
|
|
88
|
+
description: 'User ID',
|
|
89
|
+
schema: createIntegerSchema(),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const requiredParam = createRequiredParameter({
|
|
93
|
+
schema: createStringSchema(),
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
##### HTTP Request Factories
|
|
98
|
+
|
|
99
|
+
Create ThymianHttpRequest objects:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { createHttpRequest, createGetRequest, createPostRequest, createPutRequest, createPatchRequest, createDeleteRequest } from '@thymian/core-testing';
|
|
103
|
+
|
|
104
|
+
const getRequest = createGetRequest({
|
|
105
|
+
path: '/api/users',
|
|
106
|
+
queryParameters: {
|
|
107
|
+
page: createParameter({ schema: createIntegerSchema() }),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const postRequest = createPostRequest({
|
|
112
|
+
path: '/api/users',
|
|
113
|
+
body: createObjectSchema({
|
|
114
|
+
name: createStringSchema(),
|
|
115
|
+
email: createStringSchema(),
|
|
116
|
+
}),
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
##### HTTP Response Factories
|
|
121
|
+
|
|
122
|
+
Create ThymianHttpResponse objects:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { createHttpResponse, createOkResponse, createCreatedResponse, createNoContentResponse, createBadRequestResponse, createUnauthorizedResponse, createForbiddenResponse, createNotFoundResponse, createInternalServerErrorResponse } from '@thymian/core-testing';
|
|
126
|
+
|
|
127
|
+
const okResponse = createOkResponse({
|
|
128
|
+
schema: createObjectSchema({
|
|
129
|
+
id: createIntegerSchema(),
|
|
130
|
+
name: createStringSchema(),
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const errorResponse = createNotFoundResponse({
|
|
135
|
+
description: 'User not found',
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
##### ThymianFormat Factories
|
|
140
|
+
|
|
141
|
+
Create ThymianFormat instances:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { createThymianFormat, createThymianFormatWithTransaction, createThymianFormatWithTransactions } from '@thymian/core-testing';
|
|
145
|
+
|
|
146
|
+
// Empty format
|
|
147
|
+
const format = createThymianFormat();
|
|
148
|
+
|
|
149
|
+
// Format with one transaction
|
|
150
|
+
const formatWithOne = createThymianFormatWithTransaction(createGetRequest({ path: '/users' }), createOkResponse());
|
|
151
|
+
|
|
152
|
+
// Format with multiple transactions
|
|
153
|
+
const formatWithMany = createThymianFormatWithTransactions([
|
|
154
|
+
[createGetRequest({ path: '/users' }), createOkResponse()],
|
|
155
|
+
[createPostRequest({ path: '/users' }), createCreatedResponse()],
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
// Format with 10 transactions
|
|
159
|
+
const formatWithSpecificNumber = createThymianFormatWithTransactions(10);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Mocks
|
|
163
|
+
|
|
164
|
+
##### Logger Mock
|
|
165
|
+
|
|
166
|
+
Create mock Logger instances:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { createMockLogger, createSilentMockLogger } from '@thymian/core-testing';
|
|
170
|
+
|
|
171
|
+
// Standard mock (with vi.fn() spies)
|
|
172
|
+
const logger = createMockLogger({ namespace: 'test-plugin' });
|
|
173
|
+
logger.info('Starting plugin');
|
|
174
|
+
expect(logger.info).toHaveBeenCalledWith('Starting plugin');
|
|
175
|
+
|
|
176
|
+
// Silent logger (no spies, just no-ops)
|
|
177
|
+
const silentLogger = createSilentMockLogger();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
##### Emitter Mock
|
|
181
|
+
|
|
182
|
+
Create mock ThymianEmitter instances:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { createMockEmitter, createEmitterWithHandlers, createEmitterWithActionHandlers, captureEmittedEvents } from '@thymian/core-testing';
|
|
186
|
+
|
|
187
|
+
// Standard mock with spies
|
|
188
|
+
const emitter = createMockEmitter();
|
|
189
|
+
await emitter.emit('core.register', { plugin: myPlugin });
|
|
190
|
+
expect(emitter.emit).toHaveBeenCalledWith('core.register', expect.any(Object));
|
|
191
|
+
|
|
192
|
+
// Emitter with pre-configured handlers
|
|
193
|
+
const emitterWithHandlers = createEmitterWithHandlers({
|
|
194
|
+
'core.error': vi.fn(),
|
|
195
|
+
'core.register': vi.fn(),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Capture all emitted events
|
|
199
|
+
const events = captureEmittedEvents(emitter);
|
|
200
|
+
await emitter.emit('core.register', { plugin: myPlugin });
|
|
201
|
+
expect(events).toHaveLength(1);
|
|
202
|
+
expect(events[0][0]).toBe('core.register');
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
##### Plugin Mock
|
|
206
|
+
|
|
207
|
+
Create mock ThymianPlugin instances:
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { createMockPlugin, createSpyPluginFn, createPluginThatEmits, createPluginWithMetadata } from '@thymian/core-testing';
|
|
211
|
+
|
|
212
|
+
// Basic mock plugin
|
|
213
|
+
const plugin = createMockPlugin({
|
|
214
|
+
name: 'test-plugin',
|
|
215
|
+
version: '1.0.0',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Plugin with spy function
|
|
219
|
+
const pluginFn = createSpyPluginFn(async (emitter, logger, options) => {
|
|
220
|
+
logger.info('Plugin started');
|
|
221
|
+
});
|
|
222
|
+
const pluginWithSpy = createMockPlugin({ plugin: pluginFn });
|
|
223
|
+
|
|
224
|
+
// Plugin that emits events
|
|
225
|
+
const emittingPlugin = createPluginThatEmits('core.register', {
|
|
226
|
+
plugin: myPlugin,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Plugin with metadata
|
|
230
|
+
const pluginWithMeta = createPluginWithMetadata({
|
|
231
|
+
name: 'my-plugin',
|
|
232
|
+
version: '1.0.0',
|
|
233
|
+
events: {
|
|
234
|
+
emits: ['core.register'],
|
|
235
|
+
listensOn: ['core.ready'],
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Examples
|
|
241
|
+
|
|
242
|
+
#### Testing a Plugin
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { describe, it, expect } from 'vitest';
|
|
246
|
+
import { createMockEmitter, createMockLogger } from '@thymian/core-testing';
|
|
247
|
+
import { myPlugin } from './my-plugin.js';
|
|
248
|
+
|
|
249
|
+
describe('myPlugin', () => {
|
|
250
|
+
it('should register itself', async () => {
|
|
251
|
+
const emitter = createMockEmitter();
|
|
252
|
+
const logger = createMockLogger();
|
|
253
|
+
|
|
254
|
+
await myPlugin(emitter, logger, { cwd: '/test' });
|
|
255
|
+
|
|
256
|
+
expect(emitter.emit).toHaveBeenCalledWith(
|
|
257
|
+
'core.register',
|
|
258
|
+
expect.objectContaining({
|
|
259
|
+
plugin: expect.any(Object),
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('should log startup message', async () => {
|
|
265
|
+
const emitter = createMockEmitter();
|
|
266
|
+
const logger = createMockLogger();
|
|
267
|
+
|
|
268
|
+
await myPlugin(emitter, logger, { cwd: '/test' });
|
|
269
|
+
|
|
270
|
+
expect(logger.info).toHaveBeenCalledWith('Plugin started');
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### Testing Format Transformations
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import { describe, it, expect } from 'vitest';
|
|
279
|
+
import { createThymianFormat, createGetRequest, createOkResponse } from '@thymian/core-testing';
|
|
280
|
+
import { transformFormat } from './transform.js';
|
|
281
|
+
|
|
282
|
+
describe('transformFormat', () => {
|
|
283
|
+
it('should transform HTTP transactions', () => {
|
|
284
|
+
const format = createThymianFormat();
|
|
285
|
+
const request = createGetRequest({ path: '/users' });
|
|
286
|
+
const response = createOkResponse();
|
|
287
|
+
|
|
288
|
+
format.addHttpTransaction(request, response);
|
|
289
|
+
|
|
290
|
+
const result = transformFormat(format);
|
|
291
|
+
|
|
292
|
+
expect(result.getHttpTransactions()).toHaveLength(1);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
> **Getting started with Thymian?** See the [main Thymian package](https://www.npmjs.com/package/thymian) for quick installation and first-run instructions.
|
|
298
|
+
|
|
299
|
+
<!-- FOOTER:START - Do not remove or modify this section -->
|
|
300
|
+
|
|
301
|
+
## 📚 Documentation
|
|
302
|
+
|
|
303
|
+
- **[Getting Started](https://thymian.dev/introduction/getting-started)** - Set up Thymian in minutes
|
|
304
|
+
- **[Documentation](https://thymian.dev)** - Comprehensive guides and API reference
|
|
305
|
+
- **[CLI Reference](https://thymian.dev/references/cli)** - Complete CLI command documentation
|
|
306
|
+
- **[HTTP Rules](https://thymian.dev/guides/http-rules/how-to-use-rules)** - Learn about HTTP conformance validation
|
|
307
|
+
|
|
308
|
+
## 🏢 Enterprise Support
|
|
309
|
+
|
|
310
|
+
Get professional consulting and dedicated support from the creators of Thymian. We offer:
|
|
311
|
+
|
|
312
|
+
- API design and governance strategies
|
|
313
|
+
- HTTP standards compliance auditing
|
|
314
|
+
- Custom plugin development
|
|
315
|
+
- Custom rule development
|
|
316
|
+
- Team training and workshops
|
|
317
|
+
|
|
318
|
+
**[Learn more about Enterprise Support](https://thymian.dev/enterprise)** | **Email: [support@thymian.dev](mailto:support@thymian.dev)**
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
<div align="center">
|
|
323
|
+
|
|
324
|
+
**Shipped with 🌱 by [qupaya](https://qupaya.com)**
|
|
325
|
+
|
|
326
|
+
</div>
|
|
327
|
+
<!-- FOOTER:END -->
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ThymianHttpRequest } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ThymianHttpRequest with sensible defaults.
|
|
4
|
+
* All properties can be overridden.
|
|
5
|
+
*
|
|
6
|
+
* @param overrides - Partial request to override defaults
|
|
7
|
+
* @returns A complete ThymianHttpRequest object
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const getRequest = createHttpRequest({ method: 'GET', path: '/users' });
|
|
12
|
+
* const postRequest = createHttpRequest({
|
|
13
|
+
* method: 'POST',
|
|
14
|
+
* path: '/users',
|
|
15
|
+
* body: createObjectSchema()
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createHttpRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a GET request
|
|
22
|
+
*/
|
|
23
|
+
export declare function createGetRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a POST request
|
|
26
|
+
*/
|
|
27
|
+
export declare function createPostRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a PUT request
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPutRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a PATCH request
|
|
34
|
+
*/
|
|
35
|
+
export declare function createPatchRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a DELETE request
|
|
38
|
+
*/
|
|
39
|
+
export declare function createDeleteRequest(overrides?: Partial<ThymianHttpRequest>): ThymianHttpRequest;
|
|
40
|
+
//# sourceMappingURL=http-request.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.factory.d.ts","sourceRoot":"","sources":["../../src/factories/http-request.factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAmBpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAKpB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAMpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAMpB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAMpB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC1C,kBAAkB,CAKpB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a ThymianHttpRequest with sensible defaults.
|
|
3
|
+
* All properties can be overridden.
|
|
4
|
+
*
|
|
5
|
+
* @param overrides - Partial request to override defaults
|
|
6
|
+
* @returns A complete ThymianHttpRequest object
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const getRequest = createHttpRequest({ method: 'GET', path: '/users' });
|
|
11
|
+
* const postRequest = createHttpRequest({
|
|
12
|
+
* method: 'POST',
|
|
13
|
+
* path: '/users',
|
|
14
|
+
* body: createObjectSchema()
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function createHttpRequest(overrides = {}) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'http-request',
|
|
21
|
+
label: overrides.label ||
|
|
22
|
+
`${overrides.method || 'GET'} ${overrides.path || '/'}`,
|
|
23
|
+
host: 'localhost',
|
|
24
|
+
port: 443,
|
|
25
|
+
protocol: 'https',
|
|
26
|
+
path: '/',
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: {},
|
|
29
|
+
queryParameters: {},
|
|
30
|
+
cookies: {},
|
|
31
|
+
pathParameters: {},
|
|
32
|
+
mediaType: '',
|
|
33
|
+
sourceName: 'test-source',
|
|
34
|
+
...overrides,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a GET request
|
|
39
|
+
*/
|
|
40
|
+
export function createGetRequest(overrides = {}) {
|
|
41
|
+
return createHttpRequest({
|
|
42
|
+
method: 'GET',
|
|
43
|
+
...overrides,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a POST request
|
|
48
|
+
*/
|
|
49
|
+
export function createPostRequest(overrides = {}) {
|
|
50
|
+
return createHttpRequest({
|
|
51
|
+
method: 'POST',
|
|
52
|
+
mediaType: 'application/json',
|
|
53
|
+
...overrides,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a PUT request
|
|
58
|
+
*/
|
|
59
|
+
export function createPutRequest(overrides = {}) {
|
|
60
|
+
return createHttpRequest({
|
|
61
|
+
method: 'PUT',
|
|
62
|
+
mediaType: 'application/json',
|
|
63
|
+
...overrides,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates a PATCH request
|
|
68
|
+
*/
|
|
69
|
+
export function createPatchRequest(overrides = {}) {
|
|
70
|
+
return createHttpRequest({
|
|
71
|
+
method: 'PATCH',
|
|
72
|
+
mediaType: 'application/json',
|
|
73
|
+
...overrides,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a DELETE request
|
|
78
|
+
*/
|
|
79
|
+
export function createDeleteRequest(overrides = {}) {
|
|
80
|
+
return createHttpRequest({
|
|
81
|
+
method: 'DELETE',
|
|
82
|
+
...overrides,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=http-request.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.factory.js","sourceRoot":"","sources":["../../src/factories/http-request.factory.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAAyC,EAAE;IAE3C,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,KAAK,EACH,SAAS,CAAC,KAAK;YACf,GAAG,SAAS,CAAC,MAAM,IAAI,KAAK,IAAI,SAAS,CAAC,IAAI,IAAI,GAAG,EAAE;QACzD,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,EAAE;QACnB,OAAO,EAAE,EAAE;QACX,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,aAAa;QACzB,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAAyC,EAAE;IAE3C,OAAO,iBAAiB,CAAC;QACvB,MAAM,EAAE,KAAK;QACb,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAAyC,EAAE;IAE3C,OAAO,iBAAiB,CAAC;QACvB,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,kBAAkB;QAC7B,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAAyC,EAAE;IAE3C,OAAO,iBAAiB,CAAC;QACvB,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,kBAAkB;QAC7B,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,YAAyC,EAAE;IAE3C,OAAO,iBAAiB,CAAC;QACvB,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,kBAAkB;QAC7B,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAyC,EAAE;IAE3C,OAAO,iBAAiB,CAAC;QACvB,MAAM,EAAE,QAAQ;QAChB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ThymianHttpResponse } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ThymianHttpResponse with sensible defaults.
|
|
4
|
+
* All properties can be overridden.
|
|
5
|
+
*
|
|
6
|
+
* @param overrides - Partial response to override defaults
|
|
7
|
+
* @returns A complete ThymianHttpResponse object
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const okResponse = createHttpResponse({ statusCode: 200 });
|
|
12
|
+
* const errorResponse = createHttpResponse({
|
|
13
|
+
* statusCode: 404,
|
|
14
|
+
* description: 'Not Found'
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function createHttpResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a 200 OK response
|
|
21
|
+
*/
|
|
22
|
+
export declare function createOkResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a 201 Created response
|
|
25
|
+
*/
|
|
26
|
+
export declare function createCreatedResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a 204 No Content response
|
|
29
|
+
*/
|
|
30
|
+
export declare function createNoContentResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a 400 Bad Request response
|
|
33
|
+
*/
|
|
34
|
+
export declare function createBadRequestResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a 401 Unauthorized response
|
|
37
|
+
*/
|
|
38
|
+
export declare function createUnauthorizedResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a 403 Forbidden response
|
|
41
|
+
*/
|
|
42
|
+
export declare function createForbiddenResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a 404 Not Found response
|
|
45
|
+
*/
|
|
46
|
+
export declare function createNotFoundResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a 500 Internal Server Error response
|
|
49
|
+
*/
|
|
50
|
+
export declare function createInternalServerErrorResponse(overrides?: Partial<ThymianHttpResponse>): ThymianHttpResponse;
|
|
51
|
+
//# sourceMappingURL=http-response.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.factory.d.ts","sourceRoot":"","sources":["../../src/factories/http-response.factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAWrB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAOrB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC3C,mBAAmB,CAMrB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a ThymianHttpResponse with sensible defaults.
|
|
3
|
+
* All properties can be overridden.
|
|
4
|
+
*
|
|
5
|
+
* @param overrides - Partial response to override defaults
|
|
6
|
+
* @returns A complete ThymianHttpResponse object
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const okResponse = createHttpResponse({ statusCode: 200 });
|
|
11
|
+
* const errorResponse = createHttpResponse({
|
|
12
|
+
* statusCode: 404,
|
|
13
|
+
* description: 'Not Found'
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function createHttpResponse(overrides = {}) {
|
|
18
|
+
const statusCode = overrides.statusCode || 200;
|
|
19
|
+
return {
|
|
20
|
+
type: 'http-response',
|
|
21
|
+
label: overrides.label || `Response ${statusCode}`,
|
|
22
|
+
statusCode,
|
|
23
|
+
headers: {},
|
|
24
|
+
mediaType: 'application/json',
|
|
25
|
+
sourceName: 'test-source',
|
|
26
|
+
...overrides,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a 200 OK response
|
|
31
|
+
*/
|
|
32
|
+
export function createOkResponse(overrides = {}) {
|
|
33
|
+
return createHttpResponse({
|
|
34
|
+
statusCode: 200,
|
|
35
|
+
description: 'OK',
|
|
36
|
+
...overrides,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a 201 Created response
|
|
41
|
+
*/
|
|
42
|
+
export function createCreatedResponse(overrides = {}) {
|
|
43
|
+
return createHttpResponse({
|
|
44
|
+
statusCode: 201,
|
|
45
|
+
description: 'Created',
|
|
46
|
+
...overrides,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a 204 No Content response
|
|
51
|
+
*/
|
|
52
|
+
export function createNoContentResponse(overrides = {}) {
|
|
53
|
+
return createHttpResponse({
|
|
54
|
+
statusCode: 204,
|
|
55
|
+
description: 'No Content',
|
|
56
|
+
mediaType: '',
|
|
57
|
+
...overrides,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a 400 Bad Request response
|
|
62
|
+
*/
|
|
63
|
+
export function createBadRequestResponse(overrides = {}) {
|
|
64
|
+
return createHttpResponse({
|
|
65
|
+
statusCode: 400,
|
|
66
|
+
description: 'Bad Request',
|
|
67
|
+
...overrides,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a 401 Unauthorized response
|
|
72
|
+
*/
|
|
73
|
+
export function createUnauthorizedResponse(overrides = {}) {
|
|
74
|
+
return createHttpResponse({
|
|
75
|
+
statusCode: 401,
|
|
76
|
+
description: 'Unauthorized',
|
|
77
|
+
...overrides,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a 403 Forbidden response
|
|
82
|
+
*/
|
|
83
|
+
export function createForbiddenResponse(overrides = {}) {
|
|
84
|
+
return createHttpResponse({
|
|
85
|
+
statusCode: 403,
|
|
86
|
+
description: 'Forbidden',
|
|
87
|
+
...overrides,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a 404 Not Found response
|
|
92
|
+
*/
|
|
93
|
+
export function createNotFoundResponse(overrides = {}) {
|
|
94
|
+
return createHttpResponse({
|
|
95
|
+
statusCode: 404,
|
|
96
|
+
description: 'Not Found',
|
|
97
|
+
...overrides,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a 500 Internal Server Error response
|
|
102
|
+
*/
|
|
103
|
+
export function createInternalServerErrorResponse(overrides = {}) {
|
|
104
|
+
return createHttpResponse({
|
|
105
|
+
statusCode: 500,
|
|
106
|
+
description: 'Internal Server Error',
|
|
107
|
+
...overrides,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=http-response.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.factory.js","sourceRoot":"","sources":["../../src/factories/http-response.factory.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kBAAkB,CAChC,YAA0C,EAAE;IAE5C,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,GAAG,CAAC;IAC/C,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,YAAY,UAAU,EAAE;QAClD,UAAU;QACV,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,kBAAkB;QAC7B,UAAU,EAAE,aAAa;QACzB,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,IAAI;QACjB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,SAAS;QACtB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,YAAY;QACzB,SAAS,EAAE,EAAE;QACb,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,aAAa;QAC1B,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,cAAc;QAC3B,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,WAAW;QACxB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,WAAW;QACxB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iCAAiC,CAC/C,YAA0C,EAAE;IAE5C,OAAO,kBAAkB,CAAC;QACxB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,uBAAuB;QACpC,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Parameter } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Parameter with sensible defaults.
|
|
4
|
+
* All properties can be overridden.
|
|
5
|
+
*
|
|
6
|
+
* @param overrides - Partial parameter to override defaults
|
|
7
|
+
* @returns A complete Parameter object
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const requiredParam = createParameter({ required: true });
|
|
12
|
+
* const customParam = createParameter({
|
|
13
|
+
* description: 'User ID',
|
|
14
|
+
* required: true,
|
|
15
|
+
* schema: createIntegerSchema()
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createParameter(overrides?: Partial<Parameter>): Parameter;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a required Parameter
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRequiredParameter(overrides?: Partial<Parameter>): Parameter;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an optional Parameter
|
|
26
|
+
*/
|
|
27
|
+
export declare function createOptionalParameter(overrides?: Partial<Parameter>): Parameter;
|
|
28
|
+
//# sourceMappingURL=parameter.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter.factory.d.ts","sourceRoot":"","sources":["../../src/factories/parameter.factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI/C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,OAAO,CAAC,SAAS,CAAM,GAAG,SAAS,CAU7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,GAAE,OAAO,CAAC,SAAS,CAAM,GACjC,SAAS,CAKX;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,GAAE,OAAO,CAAC,SAAS,CAAM,GACjC,SAAS,CAKX"}
|