Skip to content

Commit 4f0b19f

Browse files
committed
chore: Updated tests after review
1 parent d5ca8d6 commit 4f0b19f

File tree

5 files changed

+17
-122
lines changed

5 files changed

+17
-122
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const PARAMETERS_SCHEMA_PATH = [
1212
'schema',
1313
]
1414

15-
const PARAMETERS_SCHEMA31_PATH = [
15+
const PATH_TO_PARAMETERS_SCHEMA31 = [
1616
'paths',
1717
'/example',
1818
'get',
@@ -25,5 +25,5 @@ describe('Openapi3 Parameters Schema', () => {
2525
runCommonSchemaTests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
2626
})
2727
describe('Openapi31 Parameters Schema', () => {
28-
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA31_PATH)
28+
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31)
2929
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const REQUEST_SCHEMA_PATH = [
1313
'schema',
1414
]
1515

16-
const PARAMETERS_SCHEMA31_PATH = [
16+
const PATH_TO_PARAMETERS_SCHEMA31 = [
1717
'paths',
1818
'/example',
1919
'post',
@@ -28,5 +28,5 @@ describe('Openapi3 Request Body Schema', () => {
2828
})
2929

3030
describe('Openapi31 Request Body Schema', () => {
31-
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA31_PATH)
31+
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31)
3232
})

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

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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'
56

67
const SUITE_ID = 'response-body-schema'
78

@@ -1629,7 +1630,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16291630
})
16301631
})
16311632

1632-
const RESPONSE_SCHEMA31_PATH = [
1633+
const PATH_TO_PARAMETERS_SCHEMA31 = [
16331634
'paths',
16341635
'/example',
16351636
'post',
@@ -1640,58 +1641,6 @@ const RESPONSE_SCHEMA31_PATH = [
16401641
'schema',
16411642
]
16421643

1643-
describe('Openapi31 ResponseBody.Schema ', () => {
1644-
test('Add union type', async () => {
1645-
const testId = 'add-union-type'
1646-
const result = await compareFiles(SUITE_ID, testId)
1647-
expect(result).toEqual(diffsMatcher([
1648-
expect.objectContaining({
1649-
action: DiffAction.add,
1650-
afterDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 1]],
1651-
type: breaking,
1652-
}),
1653-
]))
1654-
})
1655-
1656-
test('Add null to union type', async () => {
1657-
const testId = 'add-null-to-union-type'
1658-
const result = await compareFiles(SUITE_ID, testId)
1659-
expect(result).toEqual(diffsMatcher([
1660-
expect.objectContaining({
1661-
action: DiffAction.add,
1662-
afterDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 2]],
1663-
type: breaking,
1664-
}),
1665-
]))
1666-
})
1667-
1668-
test('Remove union type', async () => {
1669-
const testId = 'remove-union-type'
1670-
const result = await compareFiles(SUITE_ID, testId)
1671-
expect(result).toEqual(diffsMatcher([
1672-
expect.objectContaining({
1673-
action: DiffAction.remove,
1674-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 1]],
1675-
type: nonBreaking,
1676-
}),
1677-
]))
1678-
})
1679-
1680-
test('Remove null from union type', async () => {
1681-
const testId = 'remove-null-from-union-type'
1682-
const result = await compareFiles(SUITE_ID, testId)
1683-
expect(result).toEqual(diffsMatcher([
1684-
expect.objectContaining({
1685-
action: DiffAction.remove,
1686-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 2]],
1687-
type: nonBreaking,
1688-
}),
1689-
]))
1690-
})
1691-
1692-
test('Reorder types in union type', async () => {
1693-
const testId = 'reorder-types-in-union-type'
1694-
const result = await compareFiles(SUITE_ID, testId)
1695-
expect(result.length).toEqual(0)
1696-
})
1644+
describe('Openapi31 ResponseBody.Schema', () => {
1645+
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31, true)
16971646
})
Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { compareFiles } from '../utils'
2-
import { diffsMatcher } from '../../helper/matchers'
3-
import { breaking, DiffAction, nonBreaking } from '../../../src'
1+
import { runCommonSchema31Tests } from './templates/schema31'
42

53
const SUITE_ID = 'response-headers-schema'
64

7-
const RESPONSE_SCHEMA31_PATH = [
5+
const PATH_TO_PARAMETERS_SCHEMA31 = [
86
'paths',
97
'/example',
108
'get',
@@ -15,58 +13,6 @@ const RESPONSE_SCHEMA31_PATH = [
1513
'schema',
1614
]
1715

18-
describe('Openapi31 ResponseHeaders.Schema ', () => {
19-
test('Add union type', async () => {
20-
const testId = 'add-union-type'
21-
const result = await compareFiles(SUITE_ID, testId)
22-
expect(result).toEqual(diffsMatcher([
23-
expect.objectContaining({
24-
action: DiffAction.add,
25-
afterDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 1]],
26-
type: breaking,
27-
}),
28-
]))
29-
})
30-
31-
test('Add null to union type', async () => {
32-
const testId = 'add-null-to-union-type'
33-
const result = await compareFiles(SUITE_ID, testId)
34-
expect(result).toEqual(diffsMatcher([
35-
expect.objectContaining({
36-
action: DiffAction.add,
37-
afterDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 2]],
38-
type: breaking,
39-
}),
40-
]))
41-
})
42-
43-
test('Remove union type', async () => {
44-
const testId = 'remove-union-type'
45-
const result = await compareFiles(SUITE_ID, testId)
46-
expect(result).toEqual(diffsMatcher([
47-
expect.objectContaining({
48-
action: DiffAction.remove,
49-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 1]],
50-
type: nonBreaking,
51-
}),
52-
]))
53-
})
54-
55-
test('Remove null from union type', async () => {
56-
const testId = 'remove-null-from-union-type'
57-
const result = await compareFiles(SUITE_ID, testId)
58-
expect(result).toEqual(diffsMatcher([
59-
expect.objectContaining({
60-
action: DiffAction.remove,
61-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA31_PATH, 'type', 2]],
62-
type: nonBreaking,
63-
}),
64-
]))
65-
})
66-
67-
test('Reorder types in union type', async () => {
68-
const testId = 'reorder-types-in-union-type'
69-
const result = await compareFiles(SUITE_ID, testId)
70-
expect(result.length).toEqual(0)
71-
})
16+
describe('Openapi31 ResponseHeaders.Schema', () => {
17+
runCommonSchema31Tests(SUITE_ID, PATH_TO_PARAMETERS_SCHEMA31, true)
7218
})

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): void {
6+
export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath, isResponseSchema = false): 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: nonBreaking,
14+
type: isResponseSchema ? breaking : nonBreaking,
1515
}),
1616
]))
1717
})
@@ -23,7 +23,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath): v
2323
expect.objectContaining({
2424
action: DiffAction.add,
2525
afterDeclarationPaths: [[...commonPath, 'type', 2]],
26-
type: nonBreaking,
26+
type: isResponseSchema ? breaking : nonBreaking,
2727
}),
2828
]))
2929
})
@@ -35,7 +35,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath): v
3535
expect.objectContaining({
3636
action: DiffAction.remove,
3737
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
38-
type: breaking,
38+
type: isResponseSchema ? nonBreaking : breaking,
3939
}),
4040
]))
4141
})
@@ -47,7 +47,7 @@ export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath): v
4747
expect.objectContaining({
4848
action: DiffAction.remove,
4949
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
50-
type: breaking,
50+
type: isResponseSchema ? nonBreaking : breaking,
5151
}),
5252
]))
5353
})

0 commit comments

Comments
 (0)