| 
1 | 1 | import { compareFiles } from '../../utils'  | 
2 | 2 | import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'  | 
3 |  | -import { breaking, DiffAction, nonBreaking } from '../../../../src'  | 
 | 3 | +import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../../src'  | 
4 | 4 | import { diffsMatcher } from '../../../helper/matchers'  | 
5 | 5 | 
 
  | 
 | 6 | +const COMPONENTS_SCHEMAS = ['components', 'schemas']  | 
 | 7 | + | 
6 | 8 | export function runCommonResponseSchema31Tests(suiteId: string, commonPath: JsonPath): void {  | 
7 |  | -  test('Add union type', async () => {  | 
8 |  | -    const testId = 'add-union-type'  | 
9 |  | -    const result = await compareFiles(suiteId, testId)  | 
10 |  | -    expect(result).toEqual(diffsMatcher([  | 
11 |  | -      expect.objectContaining({  | 
12 |  | -        action: DiffAction.add,  | 
13 |  | -        afterDeclarationPaths: [[...commonPath, 'type', 1]],  | 
14 |  | -        type: breaking,  | 
15 |  | -      }),  | 
16 |  | -    ]))  | 
17 |  | -  })  | 
 | 9 | +  describe('Union type', () => {  | 
 | 10 | +    test('Add union type', async () => {  | 
 | 11 | +      const testId = 'add-union-type'  | 
 | 12 | +      const result = await compareFiles(suiteId, testId)  | 
 | 13 | +      expect(result).toEqual(diffsMatcher([  | 
 | 14 | +        expect.objectContaining({  | 
 | 15 | +          action: DiffAction.add,  | 
 | 16 | +          afterDeclarationPaths: [[...commonPath, 'type', 1]],  | 
 | 17 | +          type: breaking,  | 
 | 18 | +        }),  | 
 | 19 | +      ]))  | 
 | 20 | +    })  | 
18 | 21 | 
 
  | 
19 |  | -  test('Add null to union type', async () => {  | 
20 |  | -    const testId = 'add-null-to-union-type'  | 
21 |  | -    const result = await compareFiles(suiteId, testId)  | 
22 |  | -    expect(result).toEqual(diffsMatcher([  | 
23 |  | -      expect.objectContaining({  | 
24 |  | -        action: DiffAction.add,  | 
25 |  | -        afterDeclarationPaths: [[...commonPath, 'type', 2]],  | 
26 |  | -        type: breaking,  | 
27 |  | -      }),  | 
28 |  | -    ]))  | 
29 |  | -  })  | 
 | 22 | +    test('Add null to union type', async () => {  | 
 | 23 | +      const testId = 'add-null-to-union-type'  | 
 | 24 | +      const result = await compareFiles(suiteId, testId)  | 
 | 25 | +      expect(result).toEqual(diffsMatcher([  | 
 | 26 | +        expect.objectContaining({  | 
 | 27 | +          action: DiffAction.add,  | 
 | 28 | +          afterDeclarationPaths: [[...commonPath, 'type', 2]],  | 
 | 29 | +          type: breaking,  | 
 | 30 | +        }),  | 
 | 31 | +      ]))  | 
 | 32 | +    })  | 
30 | 33 | 
 
  | 
31 |  | -  test('Remove union type', async () => {  | 
32 |  | -    const testId = 'remove-union-type'  | 
33 |  | -    const result = await compareFiles(suiteId, testId)  | 
34 |  | -    expect(result).toEqual(diffsMatcher([  | 
35 |  | -      expect.objectContaining({  | 
36 |  | -        action: DiffAction.remove,  | 
37 |  | -        beforeDeclarationPaths: [[...commonPath, 'type', 1]],  | 
38 |  | -        type: nonBreaking,  | 
39 |  | -      }),  | 
40 |  | -    ]))  | 
41 |  | -  })  | 
 | 34 | +    test('Remove union type', async () => {  | 
 | 35 | +      const testId = 'remove-union-type'  | 
 | 36 | +      const result = await compareFiles(suiteId, testId)  | 
 | 37 | +      expect(result).toEqual(diffsMatcher([  | 
 | 38 | +        expect.objectContaining({  | 
 | 39 | +          action: DiffAction.remove,  | 
 | 40 | +          beforeDeclarationPaths: [[...commonPath, 'type', 1]],  | 
 | 41 | +          type: nonBreaking,  | 
 | 42 | +        }),  | 
 | 43 | +      ]))  | 
 | 44 | +    })  | 
42 | 45 | 
 
  | 
43 |  | -  test('Remove null from union type', async () => {  | 
44 |  | -    const testId = 'remove-null-from-union-type'  | 
45 |  | -    const result = await compareFiles(suiteId, testId)  | 
46 |  | -    expect(result).toEqual(diffsMatcher([  | 
47 |  | -      expect.objectContaining({  | 
48 |  | -        action: DiffAction.remove,  | 
49 |  | -        beforeDeclarationPaths: [[...commonPath, 'type', 2]],  | 
50 |  | -        type: nonBreaking,  | 
51 |  | -      }),  | 
52 |  | -    ]))  | 
 | 46 | +    test('Remove null from union type', async () => {  | 
 | 47 | +      const testId = 'remove-null-from-union-type'  | 
 | 48 | +      const result = await compareFiles(suiteId, testId)  | 
 | 49 | +      expect(result).toEqual(diffsMatcher([  | 
 | 50 | +        expect.objectContaining({  | 
 | 51 | +          action: DiffAction.remove,  | 
 | 52 | +          beforeDeclarationPaths: [[...commonPath, 'type', 2]],  | 
 | 53 | +          type: nonBreaking,  | 
 | 54 | +        }),  | 
 | 55 | +      ]))  | 
 | 56 | +    })  | 
 | 57 | + | 
 | 58 | +    test('Reorder types in union type', async () => {  | 
 | 59 | +      const testId = 'reorder-types-in-union-type'  | 
 | 60 | +      const result = await compareFiles(suiteId, testId)  | 
 | 61 | +      expect(result).toBeEmpty()  | 
 | 62 | +    })  | 
53 | 63 |   })  | 
54 | 64 | 
 
  | 
55 |  | -  test('Reorder types in union type', async () => {  | 
56 |  | -    const testId = 'reorder-types-in-union-type'  | 
57 |  | -    const result = await compareFiles(suiteId, testId)  | 
58 |  | -    expect(result).toBeEmpty()  | 
 | 65 | +  describe('$ref sibling properties', () => {  | 
 | 66 | +    test('Add sibling description for ref', async () => {  | 
 | 67 | +      const testId = 'add-sibling-description-for-ref'  | 
 | 68 | +      const result = await compareFiles(suiteId, testId)  | 
 | 69 | +      expect(result).toEqual(diffsMatcher([  | 
 | 70 | +        expect.objectContaining({  | 
 | 71 | +          action: DiffAction.replace,  | 
 | 72 | +          afterDeclarationPaths: [[...commonPath, 'description']],  | 
 | 73 | +          beforeDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Pet', 'description']],  | 
 | 74 | +          type: annotation,  | 
 | 75 | +        }),  | 
 | 76 | +      ]))  | 
 | 77 | +    })  | 
 | 78 | + | 
 | 79 | +    test('Change sibling enum for ref', async () => {  | 
 | 80 | +      const testId = 'change-sibling-enum-for-ref'  | 
 | 81 | +      const diffs = await compareFiles(suiteId, testId)  | 
 | 82 | +      expect(diffs).toBeEmpty()  | 
 | 83 | +    })  | 
 | 84 | + | 
 | 85 | +    test('Change referenced enum when sibling exists for ref', async () => {  | 
 | 86 | +      const testId = 'change-referenced-enum-when-sibling-exists-for-ref'  | 
 | 87 | +      const result = await compareFiles(suiteId, testId)  | 
 | 88 | +      expect(result).toEqual(diffsMatcher([  | 
 | 89 | +        expect.objectContaining({  | 
 | 90 | +          action: DiffAction.add,  | 
 | 91 | +          afterDeclarationPaths: [  | 
 | 92 | +            [...COMPONENTS_SCHEMAS, 'Color', 'enum', 1],  | 
 | 93 | +            [...commonPath, 'enum', 1],  | 
 | 94 | +          ],  | 
 | 95 | +          type: risky,  | 
 | 96 | +        }),  | 
 | 97 | +      ]))  | 
 | 98 | +    })  | 
 | 99 | + | 
 | 100 | +    test('Remove sibling maxLength for ref', async () => {  | 
 | 101 | +      const testId = 'remove-sibling-maxLength-for-ref'  | 
 | 102 | +      const result = await compareFiles(suiteId, testId)  | 
 | 103 | +      expect(result).toEqual(diffsMatcher([  | 
 | 104 | +        expect.objectContaining({  | 
 | 105 | +          action: DiffAction.replace,  | 
 | 106 | +          beforeDeclarationPaths: [[...commonPath, 'maxLength']],  | 
 | 107 | +          afterDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Color', 'maxLength']],  | 
 | 108 | +          type: breaking,  | 
 | 109 | +        }),  | 
 | 110 | +      ]))  | 
 | 111 | +    })  | 
59 | 112 |   })  | 
60 | 113 | }  | 
0 commit comments