Skip to content

Commit 700ba7e

Browse files
committed
feat: Update tests
1 parent 30097c2 commit 700ba7e

File tree

14 files changed

+305
-1
lines changed

14 files changed

+305
-1
lines changed

test/document-group.test.ts

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const groupToOnePathOperationIdsMap = {
3939
'path1-post',
4040
],
4141
}
42+
43+
const groupWithOneOperationIdsMap = {
44+
[GROUP_NAME]: [
45+
'path1-post',
46+
],
47+
}
4248
const EXPECTED_RESULT_FILE = 'result.yaml'
4349

4450
describe('Document Group test', () => {
@@ -69,6 +75,21 @@ describe('Document Group test', () => {
6975
}
7076
})
7177

78+
test('should have components schema object which is referenced', async () => {
79+
const pkg = LocalRegistry.openPackage('document-group/referenced-json-schema-object', groupToOnePathOperationIdsMap)
80+
const editor = await Editor.openProject(pkg.packageId, pkg)
81+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
82+
83+
const result = await editor.run({
84+
packageId: pkg.packageId,
85+
groupName: GROUP_NAME,
86+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
87+
})
88+
for (const document of Array.from(result.documents.values())) {
89+
expect(document.data).toHaveProperty(['components', 'schemas', 'MySchema'])
90+
}
91+
})
92+
7293
test('should rename documents with matching names', async () => {
7394
const dashboard = LocalRegistry.openPackage('documents-collision', groupToOperationIdsMap2)
7495
const package1 = LocalRegistry.openPackage('documents-collision/package1')
@@ -136,7 +157,7 @@ describe('Document Group test', () => {
136157
})
137158

138159
test('should delete pathItems object which is not referenced', async () => {
139-
const pkg = LocalRegistry.openPackage('document-group/pathitems-object-which-is-not-referenced', groupToOperationIdsMap)
160+
const pkg = LocalRegistry.openPackage('document-group/not-referenced-pathitems-object', groupToOperationIdsMap)
140161
const editor = await Editor.openProject(pkg.packageId, pkg)
141162
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
142163

@@ -166,6 +187,92 @@ describe('Document Group test', () => {
166187
}
167188
})
168189

190+
describe('Chain refs', () => {
191+
const COMPONENTS_ITEM_1_PATH =['components', 'pathItems', 'componentsPathItem1']
192+
test('should have documents with keep pathItems in components', async () => {
193+
const pkg = LocalRegistry.openPackage('document-group/define-pathitems-via-reference-object-chain', groupToOnePathOperationIdsMap)
194+
const editor = await Editor.openProject(pkg.packageId, pkg)
195+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
196+
197+
const result = await editor.run({
198+
packageId: pkg.packageId,
199+
groupName: GROUP_NAME,
200+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
201+
})
202+
for (const document of Array.from(result.documents.values())) {
203+
expect(document.data).toHaveProperty([...COMPONENTS_ITEM_1_PATH, 'post'])
204+
expect(document.data).toHaveProperty([...COMPONENTS_ITEM_1_PATH, 'get'])
205+
}
206+
})
207+
208+
test('should have documents stripped of operations other than from provided group', async () => {
209+
const pkg = LocalRegistry.openPackage('document-group/define-pathitems-via-reference-object-chain', groupWithOneOperationIdsMap)
210+
const editor = await Editor.openProject(pkg.packageId, pkg)
211+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
212+
213+
const result = await editor.run({
214+
packageId: pkg.packageId,
215+
groupName: GROUP_NAME,
216+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
217+
})
218+
for (const document of Array.from(result.documents.values())) {
219+
expect(document.data).toHaveProperty([...COMPONENTS_ITEM_1_PATH, 'post'])
220+
expect(document.data).not.toHaveProperty([...COMPONENTS_ITEM_1_PATH, 'get'])
221+
}
222+
})
223+
})
224+
225+
describe('reference-object', ()=> {
226+
test('second-level-object-are-the-same-when-overriding-for-response', async () => {
227+
const pkg = LocalRegistry.openPackage('document-group/second-level-object-are-the-same-when-overriding-for-response', groupToOnePathOperationIdsMap)
228+
const editor = await Editor.openProject(pkg.packageId, pkg)
229+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
230+
231+
const result = await editor.run({
232+
packageId: pkg.packageId,
233+
groupName: GROUP_NAME,
234+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
235+
})
236+
237+
const expectedResult = load(
238+
(await loadFileAsString(pkg.projectsDir, pkg.packageId, EXPECTED_RESULT_FILE))!,
239+
)
240+
for (const document of Array.from(result.documents.values())) {
241+
expect(document.data).toEqual(expectedResult)
242+
}
243+
})
244+
245+
test('not-hang-up-when-processing-for-response-which-points-to-itself', async () => {
246+
const pkg = LocalRegistry.openPackage('document-group/not-hang-up-when-processing-for-response-which-points-to-itself', groupToOnePathOperationIdsMap)
247+
const editor = await Editor.openProject(pkg.packageId, pkg)
248+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
249+
250+
const result = await editor.run({
251+
packageId: pkg.packageId,
252+
groupName: GROUP_NAME,
253+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
254+
})
255+
256+
expect(result.documents.size).toEqual(0)
257+
})
258+
259+
test.skip('not-hang-up-when-processing-cycled-chain-for-response', async () => {
260+
const pkg = LocalRegistry.openPackage('document-group/not-hang-up-when-processing-cycled-chain-for-response', groupToOnePathOperationIdsMap)
261+
const editor = await Editor.openProject(pkg.packageId, pkg)
262+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
263+
264+
const result = await editor.run({
265+
packageId: pkg.packageId,
266+
groupName: GROUP_NAME,
267+
buildType: BUILD_TYPE.REDUCED_SOURCE_SPECIFICATIONS,
268+
})
269+
270+
for (const document of Array.from(result.documents.values())) {
271+
expect(Object.keys(document.data.components.pathItems['pathItem1']).length).toEqual(document.operationIds.length)
272+
}
273+
})
274+
})
275+
169276
describe('Merge Operations', () => {
170277
test('should have properly merged documents', async () => {
171278
await runMergeOperationsCase('basic-documents-pathitems-for-merge')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Pet Store API
4+
version: 1.0.0
5+
paths:
6+
/path1:
7+
$ref: '#/components/pathItems/componentsPathItem'
8+
components:
9+
schemas:
10+
MySchema:
11+
type: object
12+
properties:
13+
message:
14+
type: string
15+
pathItems:
16+
componentsPathItem:
17+
$ref: '#/components/pathItems/componentsPathItem1'
18+
componentsPathItem1:
19+
post:
20+
responses:
21+
'200':
22+
description: Pet successfully added
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/MySchema'
27+
get:
28+
responses:
29+
'200':
30+
description: Pet successfully added
31+
content:
32+
application/json:
33+
schema:
34+
$ref: '#/components/schemas/MySchema'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: 3.1.0
2+
paths:
3+
/path1:
4+
$ref: '#/components/pathItems/componentsPathItem'
5+
components:
6+
pathItems:
7+
componentsPathItem:
8+
post:
9+
responses:
10+
'200':
11+
$ref: '#/components/responses/SuccessResponse'
12+
responses:
13+
SuccessResponse:
14+
$ref: '#/components/responses/SuccessResponse2'
15+
SuccessResponse2:
16+
$ref: '#/components/responses/SuccessResponse'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packageId": "55",
3+
"apiType": "rest",
4+
"version": "v1",
5+
"files": [
6+
{
7+
"fileId": "1.yaml",
8+
"publish": true,
9+
"labels": [],
10+
"commitId": "6c778b1f44200bd19944a6a8eac10a4e5a21a3cd"
11+
}
12+
]
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.1.0
2+
paths:
3+
/path:
4+
$ref: '#/components/pathItems/componentsPathItem'
5+
components:
6+
pathItems:
7+
componentsPathItem:
8+
post:
9+
responses:
10+
'200':
11+
$ref: '#/components/responses/SuccessResponse'
12+
responses:
13+
SuccessResponse:
14+
$ref: '#/components/responses/SuccessResponse'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packageId": "55",
3+
"apiType": "rest",
4+
"version": "v1",
5+
"files": [
6+
{
7+
"fileId": "1.yaml",
8+
"publish": true,
9+
"labels": [],
10+
"commitId": "6c778b1f44200bd19944a6a8eac10a4e5a21a3cd"
11+
}
12+
]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packageId": "55",
3+
"apiType": "rest",
4+
"version": "v1",
5+
"files": [
6+
{
7+
"fileId": "1.yaml",
8+
"publish": true,
9+
"labels": [],
10+
"commitId": "6c778b1f44200bd19944a6a8eac10a4e5a21a3cd"
11+
}
12+
]
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: response description main
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/MySchema'
15+
post:
16+
responses:
17+
'200':
18+
description: response description main
19+
content:
20+
application/json:
21+
schema:
22+
$ref: '#/components/schemas/MySchema'
23+
24+
components:
25+
schemas:
26+
MySchema:
27+
type: object
28+
properties:
29+
message:
30+
type: string

0 commit comments

Comments
 (0)