Skip to content

Commit 6534200

Browse files
committed
fix: Update tests
1 parent 60d9975 commit 6534200

File tree

6 files changed

+80
-50
lines changed

6 files changed

+80
-50
lines changed

test/compatibility-suites/openapi/parameters-schema.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,9 @@ const PARAMETERS_SCHEMA_PATH = [
1212
'schema',
1313
]
1414

15-
const PATH_TO_PARAMETERS_SCHEMA31 = [
16-
'paths',
17-
'/example',
18-
'get',
19-
'parameters',
20-
0,
21-
'schema',
22-
]
23-
2415
describe('Openapi3 Parameters Schema', () => {
2516
runCommonSchemaTests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
2617
})
2718
describe('Openapi31 Parameters Schema', () => {
28-
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31)
19+
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
2920
})

test/compatibility-suites/openapi/request-body-schema.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,10 @@ const REQUEST_SCHEMA_PATH = [
1313
'schema',
1414
]
1515

16-
const PATH_TO_PARAMETERS_SCHEMA31 = [
17-
'paths',
18-
'/example',
19-
'post',
20-
'requestBody',
21-
'content',
22-
'application/json',
23-
'schema',
24-
]
25-
2616
describe('Openapi3 Request Body Schema', () => {
2717
runCommonSchemaTests(SUITE_ID, REQUEST_SCHEMA_PATH)
2818
})
2919

3020
describe('Openapi31 Request Body Schema', () => {
31-
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31)
21+
runCommonSchema31Tests(SUITE_ID, REQUEST_SCHEMA_PATH)
3222
})

test/compatibility-suites/openapi/response-body-schema.test.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { compareFiles, compareFilesWithMerge, TEST_DEFAULTS_DECLARATION_PATHS }
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../src'
44
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
5-
import { runCommonSchema31Tests } from './templates/schema31'
5+
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
66

77
const SUITE_ID = 'response-body-schema'
88

@@ -138,7 +138,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
138138
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
139139
type: nonBreaking,
140140
}),
141-
]
141+
],
142142
))
143143
})
144144

@@ -305,7 +305,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
305305
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minLength']],
306306
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
307307
type: breaking,
308-
})
308+
}),
309309
]))
310310
})
311311

@@ -694,7 +694,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
694694
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
695695
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
696696
type: nonBreaking,
697-
})
697+
}),
698698
]))
699699
})
700700

@@ -739,7 +739,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
739739
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
740740
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
741741
type: breaking,
742-
})
742+
}),
743743
]))
744744
})
745745

@@ -1021,7 +1021,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
10211021
beforeDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
10221022
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minProperties']],
10231023
type: nonBreaking,
1024-
})
1024+
}),
10251025
]))
10261026
})
10271027

@@ -1066,7 +1066,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
10661066
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minProperties']],
10671067
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
10681068
type: breaking,
1069-
})
1069+
}),
10701070
]))
10711071
})
10721072

@@ -1630,17 +1630,6 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16301630
})
16311631
})
16321632

1633-
const PATH_TO_PARAMETERS_SCHEMA31 = [
1634-
'paths',
1635-
'/example',
1636-
'post',
1637-
'responses',
1638-
'200',
1639-
'content',
1640-
'application/json',
1641-
'schema',
1642-
]
1643-
16441633
describe('Openapi31 ResponseBody.Schema', () => {
1645-
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31, true)
1634+
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
16461635
})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { runCommonSchema31Tests } from './templates/schema31'
1+
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
22

33
const SUITE_ID = 'response-headers-schema'
44

5-
const PATH_TO_PARAMETERS_SCHEMA31 = [
5+
const RESPONSE_SCHEMA_PATH = [
66
'paths',
7-
'/example',
8-
'get',
7+
'/path1',
8+
'post',
99
'responses',
1010
'200',
1111
'headers',
@@ -14,5 +14,5 @@ const PATH_TO_PARAMETERS_SCHEMA31 = [
1414
]
1515

1616
describe('Openapi31 ResponseHeaders.Schema', () => {
17-
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31, true)
17+
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
1818
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { compareFiles } from '../../utils'
2+
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
3+
import { breaking, DiffAction, nonBreaking } from '../../../../src'
4+
import { diffsMatcher } from '../../../helper/matchers'
5+
6+
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+
})
18+
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+
})
30+
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+
})
42+
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+
]))
53+
})
54+
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.length).toEqual(0)
59+
})
60+
}

test/compatibility-suites/openapi/templates/schema31.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
33
import { breaking, DiffAction, nonBreaking } from '../../../../src'
44
import { diffsMatcher } from '../../../helper/matchers'
55

6-
export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath, isResponseSchema = false): void {
6+
export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath): void {
77
test('Add union type', async () => {
88
const testId = 'add-union-type'
99
const result = await compareFiles(suiteId, testId)
1010
expect(result).toEqual(diffsMatcher([
1111
expect.objectContaining({
1212
action: DiffAction.add,
1313
afterDeclarationPaths: [[...commonPath, 'type', 1]],
14-
type: isResponseSchema ? breaking : nonBreaking,
14+
type: nonBreaking,
1515
}),
1616
]))
1717
})
@@ -23,7 +23,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath, is
2323
expect.objectContaining({
2424
action: DiffAction.add,
2525
afterDeclarationPaths: [[...commonPath, 'type', 2]],
26-
type: isResponseSchema ? breaking : nonBreaking,
26+
type: nonBreaking,
2727
}),
2828
]))
2929
})
@@ -35,7 +35,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath, is
3535
expect.objectContaining({
3636
action: DiffAction.remove,
3737
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
38-
type: isResponseSchema ? nonBreaking : breaking,
38+
type: breaking,
3939
}),
4040
]))
4141
})
@@ -47,7 +47,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath, is
4747
expect.objectContaining({
4848
action: DiffAction.remove,
4949
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
50-
type: isResponseSchema ? nonBreaking : breaking,
50+
type: breaking,
5151
}),
5252
]))
5353
})

0 commit comments

Comments
 (0)