Skip to content

Commit 400cfa6

Browse files
committed
feat: Added tests for Sibling properties Schema
1 parent ff4e297 commit 400cfa6

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"fast-equals": "4.0.3"
3333
},
3434
"devDependencies": {
35-
"@netcracker/qubership-apihub-compatibility-suites": "dev",
35+
"@netcracker/qubership-apihub-compatibility-suites": "feature-sibling-properties-json-schema",
3636
"@netcracker/qubership-apihub-graphapi": "1.0.8",
3737
"@netcracker/qubership-apihub-npm-gitflow": "3.1.0",
3838
"@types/jest": "29.5.11",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
22
import { runCommonSchema31Tests } from './templates/schema31'
3+
import { runSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'
34

45
const SUITE_ID = 'parameters-schema'
56

@@ -21,3 +22,7 @@ describe('Openapi3 Parameters Schema', () => {
2122
describe('Openapi31 Parameters Schema', () => {
2223
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
2324
})
25+
26+
describe('Openapi31 Parameters. Sibling properties Schema', () => {
27+
runSiblingPropertiesSchema(SUITE_ID, PARAMETERS_SCHEMA_PATH)
28+
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
22
import { runCommonSchema31Tests } from './templates/schema31'
3+
import { runSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'
34

45
const SUITE_ID = 'request-body-schema'
56

@@ -22,3 +23,7 @@ describe('Openapi3 Request Body Schema', () => {
2223
describe('Openapi31 Request Body Schema', () => {
2324
runCommonSchema31Tests(SUITE_ID, REQUEST_SCHEMA_PATH)
2425
})
26+
27+
describe('Openapi31 Request Body. Sibling properties Schema', () => {
28+
runSiblingPropertiesSchema(SUITE_ID, REQUEST_SCHEMA_PATH)
29+
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../s
44
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
55
import { runAddRemoveDefaultValuesSchemaTests } from './templates/schema'
66
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
7+
import { runResponseSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'
78

89
const SUITE_ID = 'response-body-schema'
910

@@ -1636,3 +1637,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16361637
describe('Openapi31 ResponseBody.Schema', () => {
16371638
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
16381639
})
1640+
1641+
describe('Openapi31 ResponseBody. Sibling properties Schema', () => {
1642+
runResponseSiblingPropertiesSchema(SUITE_ID, RESPONSE_SCHEMA_PATH)
1643+
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
2+
import { runResponseSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'
23

34
const SUITE_ID = 'response-headers-schema'
45

@@ -16,3 +17,7 @@ const RESPONSE_HEADERS_SCHEMA_PATH = [
1617
describe('Openapi31 ResponseHeaders.Schema', () => {
1718
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_HEADERS_SCHEMA_PATH)
1819
})
20+
21+
describe('Openapi31 ResponseHeaders. Sibling properties Schema', () => {
22+
runResponseSiblingPropertiesSchema(SUITE_ID, RESPONSE_HEADERS_SCHEMA_PATH)
23+
})
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { compareFiles } from '../../utils'
2+
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
3+
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../../src'
4+
import { diffsMatcher } from '../../../helper/matchers'
5+
6+
const COMPONENTS_SCHEMAS = ['components', 'schemas']
7+
8+
export function runResponseSiblingPropertiesSchema(suiteId: string, commonPath: JsonPath): void {
9+
runTests(suiteId, commonPath, true)
10+
}
11+
12+
export function runSiblingPropertiesSchema(suiteId: string, commonPath: JsonPath): void {
13+
runTests(suiteId, commonPath, false)
14+
}
15+
16+
function runTests(suiteId: string, commonPath: JsonPath, isResponse: boolean): void {
17+
test('Add sibling description for ref', async () => {
18+
const testId = 'add-sibling-description-for-ref'
19+
const result = await compareFiles(suiteId, testId)
20+
expect(result).toEqual(diffsMatcher([
21+
expect.objectContaining({
22+
action: DiffAction.replace,
23+
afterDeclarationPaths: [[...commonPath, 'description']],
24+
beforeDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Pet', 'description']],
25+
type: annotation,
26+
}),
27+
]))
28+
})
29+
30+
test('Change sibling enum for ref', async () => {
31+
const testId = 'change-sibling-enum-for-ref'
32+
const result = await compareFiles(suiteId, testId)
33+
expect(result.length).toEqual(0)
34+
})
35+
36+
test('Change referenced enum when sibling exists for ref', async () => {
37+
const testId = 'change-referenced-enum-when-sibling-exists-for-ref'
38+
const result = await compareFiles(suiteId, testId)
39+
expect(result).toEqual(diffsMatcher([
40+
expect.objectContaining({
41+
action: DiffAction.add,
42+
afterDeclarationPaths: [
43+
[...COMPONENTS_SCHEMAS, 'Color', 'enum', 1],
44+
[...commonPath, 'enum', 1],
45+
],
46+
type: isResponse ? risky : nonBreaking,
47+
}),
48+
]))
49+
})
50+
51+
test('Remove sibling maxLength for ref', async () => {
52+
const testId = 'remove-sibling-maxLength-for-ref'
53+
const result = await compareFiles(suiteId, testId)
54+
expect(result).toEqual(diffsMatcher([
55+
expect.objectContaining({
56+
action: DiffAction.replace,
57+
beforeDeclarationPaths: [[...commonPath, 'maxLength']],
58+
afterDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Color', 'maxLength']],
59+
type: isResponse ? breaking : nonBreaking,
60+
}),
61+
]))
62+
})
63+
}

0 commit comments

Comments
 (0)