|
1 | 1 | import { assertNone, assertSome } from '@stoplight/prism-core/src/utils/__tests__/utils';
|
2 | 2 | import { HttpParamStyles } from '@stoplight/types';
|
3 |
| -import { generate } from '../HttpParamGenerator'; |
| 3 | +import { generate, improveSchema } from '../HttpParamGenerator'; |
4 | 4 |
|
5 | 5 | describe('HttpParamGenerator', () => {
|
6 | 6 | describe('generate()', () => {
|
@@ -50,4 +50,50 @@ describe('HttpParamGenerator', () => {
|
50 | 50 | });
|
51 | 51 | });
|
52 | 52 | });
|
| 53 | + |
| 54 | + describe('improveSchema()', () => { |
| 55 | + describe.each(['number', 'integer'])('when feed with a %s', type => { |
| 56 | + // @ts-ignore |
| 57 | + const improvedSchema = improveSchema({ type }); |
| 58 | + |
| 59 | + it('should have a minimum and a maximum', () => { |
| 60 | + expect(improvedSchema).toHaveProperty('minimum', 1); |
| 61 | + expect(improvedSchema).toHaveProperty('maximum', 1000); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + describe('when feed with string', () => { |
| 66 | + describe('no format and no enum', () => { |
| 67 | + const improvedSchema = improveSchema({ type: 'string' }); |
| 68 | + |
| 69 | + it('should have the x-faker extension', () => { |
| 70 | + expect(improvedSchema).toHaveProperty('x-faker', 'lorem.word'); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe.each<{ 0: string; 1: object }>([['format', { format: 'email' }], ['enum', { enum: [1, 2, 3] }], ['pattern', { pattern: '^[A-Z]+$' }]])( |
| 75 | + 'when with %s', |
| 76 | + (_a, additional) => { |
| 77 | + const improvedSchema = improveSchema({ type: 'string', ...additional }); |
| 78 | + |
| 79 | + it('should not have the x-faker extension', () => expect(improvedSchema).not.toHaveProperty('x-faker')); |
| 80 | + }, |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + describe('when feed with object', () => { |
| 85 | + describe('no format and no enum', () => { |
| 86 | + const improvedSchema = improveSchema({ |
| 87 | + type: 'object', |
| 88 | + properties: { a: { type: 'string' }, b: { type: 'number' } }, |
| 89 | + }); |
| 90 | + |
| 91 | + it('will recursively improve the schema', () => { |
| 92 | + expect(improvedSchema).toHaveProperty('properties.a.x-faker', 'lorem.word'); |
| 93 | + expect(improvedSchema).toHaveProperty('properties.b.minimum', 1); |
| 94 | + expect(improvedSchema).toHaveProperty('properties.b.maximum', 1000); |
| 95 | + }); |
| 96 | + }); |
| 97 | + }); |
| 98 | + }); |
53 | 99 | });
|
0 commit comments