|
| 1 | +import { annotation, apiDiff, DiffAction } from '../src' |
| 2 | +import { OpenapiBuilder } from './helper' |
| 3 | +import { diffsMatcher } from './helper/matchers' |
| 4 | + |
| 5 | +describe('Path and method mapping', () => { |
| 6 | + let openapiBuilder: OpenapiBuilder |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + openapiBuilder = new OpenapiBuilder() |
| 10 | + }) |
| 11 | + |
| 12 | + it('Move prefix from server to path', () => { |
| 13 | + const before = openapiBuilder |
| 14 | + .addServer('https://example1.com/api/v2') |
| 15 | + .addPath({ |
| 16 | + path: '/path1', |
| 17 | + responses: { |
| 18 | + '200': { |
| 19 | + description: 'OK', |
| 20 | + }, |
| 21 | + }, |
| 22 | + }) |
| 23 | + .getSpec() |
| 24 | + |
| 25 | + openapiBuilder.reset() |
| 26 | + |
| 27 | + const after = openapiBuilder |
| 28 | + .addServer('https://example1.com') |
| 29 | + .addPath({ |
| 30 | + path: '/api/v2/path1', responses: { |
| 31 | + '200': { |
| 32 | + description: 'not OK', |
| 33 | + }, |
| 34 | + }, |
| 35 | + }) |
| 36 | + .getSpec() |
| 37 | + |
| 38 | + const { diffs } = apiDiff(before, after) |
| 39 | + |
| 40 | + expect(diffs).toEqual(diffsMatcher([ |
| 41 | + expect.objectContaining({ |
| 42 | + beforeDeclarationPaths: [['paths', '/path1']], |
| 43 | + afterDeclarationPaths: [['paths', '/api/v2/path1']], |
| 44 | + action: DiffAction.rename, |
| 45 | + type: annotation, |
| 46 | + }), |
| 47 | + expect.objectContaining({ |
| 48 | + beforeDeclarationPaths: [['paths', '/path1', 'get', 'responses', '200', 'description']], |
| 49 | + afterDeclarationPaths: [['paths', '/api/v2/path1', 'get', 'responses', '200', 'description']], |
| 50 | + action: DiffAction.replace, |
| 51 | + type: annotation, |
| 52 | + }), |
| 53 | + expect.objectContaining({ |
| 54 | + beforeDeclarationPaths: [['servers', 0, 'url']], |
| 55 | + action: DiffAction.replace, |
| 56 | + type: annotation, |
| 57 | + }), |
| 58 | + ])) |
| 59 | + }) |
| 60 | +}) |
0 commit comments