Skip to content

Commit af2efb1

Browse files
committed
feat: Added compatibility-suites tests
1 parent f7f805c commit af2efb1

File tree

8 files changed

+124
-1
lines changed

8 files changed

+124
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
2+
3+
const SUITE_ID = 'headers'
4+
const PATH_TO_HEADER_DESCRIPTION = ['paths', '/user/login', 'get', 'responses', '200', 'headers', 'X-Rate-Limit']
5+
const PATH_TO_COMPONENT_DESCRIPTION = ['components', 'headers', 'X-Rate-Limit', 'description']
6+
7+
describe('Reference object. Headers. Description fields in ref object', () => {
8+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_HEADER_DESCRIPTION, PATH_TO_COMPONENT_DESCRIPTION)
9+
})

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles, TEST_DEFAULTS_DECLARATION_PATHS } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, deprecated, DiffAction, nonBreaking, unclassified } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'operation-parameters'
67

@@ -338,7 +339,6 @@ describe('Openapi3 Operation Parameters', () => {
338339
}),
339340
]))
340341
})
341-
342342

343343
// TODO: fixme
344344
test.skip('Mark primitive parameter as exploded', async () => {
@@ -724,3 +724,10 @@ describe('Openapi3 Operation Parameters', () => {
724724
})
725725
})
726726
})
727+
728+
const PATH_TO_OPERATION_PARAMETERS_DESCRIPTION = ['paths', '/pet/findByStatus', 'get', 'parameters', 0]
729+
const PATH_TO_COMPONENT_DESCRIPTION = ['components', 'parameters', 'status', 'description']
730+
731+
describe('Reference object. Operation parameters. Description fields in ref object', () => {
732+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_OPERATION_PARAMETERS_DESCRIPTION, PATH_TO_COMPONENT_DESCRIPTION)
733+
})

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests, runRefObjectSummaryTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'parameters-examples'
67

@@ -168,3 +169,12 @@ describe('Openapi3 Parameters Examples', () => {
168169
]))
169170
})
170171
})
172+
173+
const PATH_TO_RESPONSES_DESCRIPTION = ['paths', '/pet/findByTags', 'get', 'parameters', 0, 'examples', 'ex1']
174+
const PATH_TO_COMPONENTS = ['components', 'examples', 'ex1']
175+
176+
describe('Reference object. Parameters examples. Description and Summary fields in ref object', () => {
177+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_RESPONSES_DESCRIPTION, [...PATH_TO_COMPONENTS, 'description'])
178+
runRefObjectSummaryTests(SUITE_ID, PATH_TO_RESPONSES_DESCRIPTION, [...PATH_TO_COMPONENTS, 'summary'])
179+
})
180+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'request-body-examples'
67

@@ -166,3 +167,10 @@ describe('Openapi3 Request Body Examples', () => {
166167
]))
167168
})
168169
})
170+
171+
const PATH_TO_REQUEST_BODY_DESCRIPTION = ['paths', '/pet', 'post', 'requestBody', 'content', 'application/json', 'examples', 'ex1']
172+
const PATH_TO_COMPONENTS_DESCRIPTION = ['components', 'examples', 'ex1', 'description']
173+
174+
describe('Reference object. Request body examples. Description fields in ref object', () => {
175+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_REQUEST_BODY_DESCRIPTION, PATH_TO_COMPONENTS_DESCRIPTION)
176+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
2+
3+
const SUITE_ID = 'request-body'
4+
const PATH_TO_HEADER_DESCRIPTION = ['paths', '/store/order', 'post', 'requestBody']
5+
const PATH_TO_COMPONENTS_DESCRIPTION = ['components', 'requestBodies', 'rb1', 'description']
6+
7+
describe('Reference object. Request body. Description fields in ref object', () => {
8+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_HEADER_DESCRIPTION, PATH_TO_COMPONENTS_DESCRIPTION)
9+
})

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'response-body-examples'
67

@@ -161,3 +162,10 @@ describe('Openapi3 Response Body Examples', () => {
161162
]))
162163
})
163164
})
165+
166+
const PATH_TO_RESPONSES_DESCRIPTION = ['paths', '/pet', 'post', 'responses', '200', 'content', 'application/json', 'examples', 'ex1']
167+
const PATH_TO_COMPONENTS_DESCRIPTION = ['components', 'examples', 'ex1', 'description']
168+
169+
describe('Reference object. Response body examples. Description fields in ref object', () => {
170+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_RESPONSES_DESCRIPTION, PATH_TO_COMPONENTS_DESCRIPTION)
171+
})

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, DiffAction, nonBreaking } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'response'
67

@@ -252,3 +253,10 @@ describe('Openapi3 Response', () => {
252253
})
253254
})
254255
})
256+
257+
const PATH_TO_RESPONSES_DESCRIPTION = ['paths', '/pet', 'post', 'responses', '200']
258+
const PATH_TO_COMPONENTS_DESCRIPTION = ['components', 'responses', 'response200', 'description']
259+
260+
describe('Reference object. Response. Description fields in ref object', () => {
261+
runRefObjectDescriptionTests(SUITE_ID, PATH_TO_RESPONSES_DESCRIPTION, PATH_TO_COMPONENTS_DESCRIPTION)
262+
})
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
2+
import { compareFiles } from '../../utils'
3+
import { diffsMatcher } from '../../../helper/matchers'
4+
import { annotation, DiffAction } from '../../../../src'
5+
6+
const enum OverridenFields {
7+
DESCRIPTION = 'description',
8+
SUMMARY = 'summary'
9+
}
10+
11+
export function runRefObjectDescriptionTests(suiteId: string, commonPath: JsonPath, componentPath: JsonPath): void {
12+
runReferenceObjectTests(suiteId, commonPath, componentPath, OverridenFields.DESCRIPTION)
13+
}
14+
15+
export function runRefObjectSummaryTests(suiteId: string, commonPath: JsonPath, componentPath: JsonPath): void {
16+
runReferenceObjectTests(suiteId, commonPath, componentPath, OverridenFields.SUMMARY)
17+
}
18+
19+
function runReferenceObjectTests(suiteId: string, commonPath: JsonPath, componentPath: JsonPath, overridenField: OverridenFields): void {
20+
test(`Add overriden ${overridenField}`, async () => {
21+
const testId = `add-overriden-${overridenField}`
22+
const result = await compareFiles(suiteId, testId)
23+
expect(result).toEqual(diffsMatcher([
24+
expect.objectContaining({
25+
action: DiffAction.replace,
26+
afterDeclarationPaths: [commonPath],
27+
beforeDeclarationPaths: [componentPath],
28+
type: annotation,
29+
}),
30+
]))
31+
})
32+
33+
test(`Remove overriden ${overridenField}`, async () => {
34+
const testId = `remove-overriden-${overridenField}`
35+
const result = await compareFiles(suiteId, testId)
36+
expect(result).toEqual(diffsMatcher([
37+
expect.objectContaining({
38+
action: DiffAction.replace,
39+
afterDeclarationPaths: [componentPath],
40+
beforeDeclarationPaths: [commonPath],
41+
type: annotation,
42+
}),
43+
]))
44+
})
45+
46+
test(`Change overriden ${overridenField}`, async () => {
47+
const testId = `change-overriden-${overridenField}`
48+
const result = await compareFiles(suiteId, testId)
49+
expect(result).toEqual(diffsMatcher([
50+
expect.objectContaining({
51+
action: DiffAction.replace,
52+
afterDeclarationPaths: [commonPath],
53+
beforeDeclarationPaths: [commonPath],
54+
type: annotation,
55+
}),
56+
]))
57+
})
58+
59+
test(`Change referenced ${overridenField} when overridden exists`, async () => {
60+
const testId = `change-referenced-${overridenField}-when-overridden-exists`
61+
const result = await compareFiles(suiteId, testId)
62+
expect(result.length).toEqual(0)
63+
})
64+
}

0 commit comments

Comments
 (0)