Skip to content

Commit 00c574f

Browse files
committed
test: add missing cases
1 parent e820f6b commit 00c574f

File tree

21 files changed

+466
-14
lines changed

21 files changed

+466
-14
lines changed

test/changes.test.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
LocalRegistry,
2222
numberOfImpactedOperationsMatcher,
2323
} from './helpers'
24-
import { ANNOTATION_CHANGE_TYPE, BREAKING_CHANGE_TYPE } from '../src'
24+
import { ANNOTATION_CHANGE_TYPE, BREAKING_CHANGE_TYPE, BUILD_TYPE, NON_BREAKING_CHANGE_TYPE } from '../src'
2525

2626
let beforePackage: LocalRegistry
2727
let afterPackage: LocalRegistry
@@ -52,17 +52,56 @@ describe('Changes test', () => {
5252
packageId: AFTER_PACKAGE_ID,
5353
previousVersionPackageId: BEFORE_PACKAGE_ID,
5454
previousVersion: BEFORE_VERSION_ID,
55-
buildType: 'changelog',
55+
buildType: BUILD_TYPE.CHANGELOG,
5656
})
57-
58-
const [{ operationTypes: [{ changesSummary }] }] = result.comparisons
59-
expect(changesSummary?.[BREAKING_CHANGE_TYPE]).toBe(1)
60-
expect(changesSummary?.[ANNOTATION_CHANGE_TYPE]).toBe(1)
57+
expect(result).toEqual(changesSummaryMatcher({
58+
[BREAKING_CHANGE_TYPE]: 1,
59+
[ANNOTATION_CHANGE_TYPE]: 1,
60+
}))
61+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
62+
[BREAKING_CHANGE_TYPE]: 1,
63+
[ANNOTATION_CHANGE_TYPE]: 1,
64+
}))
6165
})
6266

6367
test('compare parametrized operations', async () => {
64-
const result = await buildChangelogPackage('compare-parametrized-operations')
68+
const result = await buildChangelogPackage('changelog/compare-parametrized-operations')
6569
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 2}))
6670
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1}))
6771
})
72+
73+
test('add method', async () => {
74+
const result = await buildChangelogPackage('changelog/add-method')
75+
expect(result).toEqual(changesSummaryMatcher({ [NON_BREAKING_CHANGE_TYPE]: 1}))
76+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [NON_BREAKING_CHANGE_TYPE]: 1}))
77+
})
78+
79+
test('remove method', async () => {
80+
const result = await buildChangelogPackage('changelog/remove-method')
81+
expect(result).toEqual(changesSummaryMatcher({ [BREAKING_CHANGE_TYPE]: 1}))
82+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [BREAKING_CHANGE_TYPE]: 1}))
83+
})
84+
85+
test('change method content', async () => {
86+
const result = await buildChangelogPackage('changelog/change-method')
87+
88+
expect(result).toEqual(changesSummaryMatcher({
89+
[BREAKING_CHANGE_TYPE]: 1,
90+
[NON_BREAKING_CHANGE_TYPE]: 1,
91+
}))
92+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
93+
[BREAKING_CHANGE_TYPE]: 1,
94+
[NON_BREAKING_CHANGE_TYPE]: 1,
95+
}))
96+
})
97+
98+
test('should match moved operations', async () => {
99+
const result = await buildChangelogPackage(
100+
'changelog/documents-matching',
101+
[{ fileId: 'before/spec1.yaml' }, { fileId: 'before/spec2.yaml' }],
102+
[{ fileId: 'after/spec1.yaml' }, { fileId: 'after/spec2.yaml' }, { fileId: 'after/evicted.yaml' }],
103+
)
104+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 3 }))
105+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 3 }))
106+
})
68107
})

test/helpers/utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,38 @@ export async function buildChangelogPackage(
155155
return await editor.run()
156156
}
157157

158+
export async function buildPrefixGroupChangelogPackage(options: {
159+
packageId: string
160+
config?: Partial<BuildConfig>
161+
}): Promise<BuildResult> {
162+
const {
163+
packageId,
164+
config: {
165+
files = [{ fileId: 'spec.yaml' }],
166+
currentGroup = '/api/v2',
167+
previousGroup = 'api/v1',
168+
} = {},
169+
} = options ?? {}
170+
171+
const pkg = LocalRegistry.openPackage(packageId)
172+
173+
await pkg.publish(pkg.packageId, {
174+
packageId: pkg.packageId,
175+
version: BEFORE_VERSION_ID,
176+
files: files,
177+
})
178+
179+
const editor = new Editor(pkg.packageId, {
180+
version: BEFORE_VERSION_ID,
181+
packageId: pkg.packageId,
182+
currentGroup: currentGroup,
183+
previousGroup: previousGroup,
184+
buildType: BUILD_TYPE.PREFIX_GROUPS_CHANGELOG,
185+
status: VERSION_STATUS.RELEASE,
186+
})
187+
return await editor.run()
188+
}
189+
158190
export async function buildGqlChangelogPackage(
159191
packageId: string,
160192
): Promise<BuildResult> {

test/prefix-groups.test.ts

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Editor, LocalRegistry } from './helpers'
18-
import { BUILD_TYPE } from '../src'
17+
import {
18+
buildPrefixGroupChangelogPackage,
19+
changesSummaryMatcher,
20+
Editor,
21+
LocalRegistry,
22+
numberOfImpactedOperationsMatcher,
23+
} from './helpers'
24+
import { ANNOTATION_CHANGE_TYPE, BREAKING_CHANGE_TYPE, BUILD_TYPE, NON_BREAKING_CHANGE_TYPE } from '../src'
1925

2026
const pkg = LocalRegistry.openPackage('apihub')
2127

22-
describe('Prefix Groups test', () => {
23-
beforeAll(async () => {
28+
describe('Prefix Groups test', () => {
29+
test('should compare prefix groups /api/{group}, groups=v2, v3', async () => {
2430
// generate missing versions/apihub folder contents
2531
await pkg.publish(pkg.packageId, {
2632
version: 'v1',
@@ -62,18 +68,72 @@ describe('Prefix Groups test', () => {
6268
{ fileId: 'Public Registry API.yaml' },
6369
],
6470
})
65-
})
6671

67-
test('should compare prefix groups /api/{group}, groups=v2, v3', async () => {
6872
const editor = await Editor.openProject(pkg.packageId, pkg)
6973
const result = await editor.run({
7074
version: 'prefix2',
71-
previousVersion: 'prefix1',
7275
currentGroup: '/api/v3',
7376
previousGroup: 'api/v2',
7477
buildType: BUILD_TYPE.PREFIX_GROUPS_CHANGELOG,
7578
})
7679

7780
expect(result.comparisons?.[0].data?.length).toBe(95)
7881
})
82+
83+
test('should compare prefix groups /api/{group}', async () => {
84+
const result = await buildPrefixGroupChangelogPackage({ packageId: 'prefix-groups/mixed-cases' })
85+
86+
expect(result).toEqual(changesSummaryMatcher({
87+
[BREAKING_CHANGE_TYPE]: 1,
88+
[NON_BREAKING_CHANGE_TYPE]: 1,
89+
[ANNOTATION_CHANGE_TYPE]: 2,
90+
}))
91+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
92+
[BREAKING_CHANGE_TYPE]: 1,
93+
[NON_BREAKING_CHANGE_TYPE]: 1,
94+
[ANNOTATION_CHANGE_TYPE]: 2,
95+
}))
96+
})
97+
98+
test('Add method in a new version', async () => {
99+
const result = await buildPrefixGroupChangelogPackage({ packageId: 'prefix-groups/add-method' })
100+
101+
expect(result).toEqual(changesSummaryMatcher({ [NON_BREAKING_CHANGE_TYPE]: 1 }))
102+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [NON_BREAKING_CHANGE_TYPE]: 1 }))
103+
})
104+
105+
test('Remove method in a new version', async () => {
106+
const result = await buildPrefixGroupChangelogPackage({ packageId: 'prefix-groups/remove-method' })
107+
108+
expect(result).toEqual(changesSummaryMatcher({ [BREAKING_CHANGE_TYPE]: 1 }))
109+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [BREAKING_CHANGE_TYPE]: 1 }))
110+
})
111+
112+
test('Change method content in a new version', async () => {
113+
const result = await buildPrefixGroupChangelogPackage({ packageId: 'prefix-groups/change-method' })
114+
115+
expect(result).toEqual(changesSummaryMatcher({
116+
[BREAKING_CHANGE_TYPE]: 1,
117+
[NON_BREAKING_CHANGE_TYPE]: 1,
118+
}))
119+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
120+
[BREAKING_CHANGE_TYPE]: 1,
121+
[NON_BREAKING_CHANGE_TYPE]: 1,
122+
}))
123+
})
124+
125+
test('should compare prefix groups with different length', async () => {
126+
const result = await buildPrefixGroupChangelogPackage({
127+
packageId: 'prefix-groups/different-prefix-length',
128+
config: {
129+
currentGroup: '/api/v10',
130+
previousGroup: '/api/v1000',
131+
},
132+
})
133+
134+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
135+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
136+
})
137+
138+
// todo add case when api/v1 in servers and api/v2 in some paths?
79139
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content: { }
12+
post:
13+
responses:
14+
'200':
15+
description: OK
16+
content: { }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content: { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/api/v1/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/xml:
13+
schema: { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/api/v1/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema: { }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample API
4+
description: API specification example
5+
version: 1.0.0
6+
paths:
7+
/extra:
8+
post:
9+
summary: extra operation
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
properties:
16+
name:
17+
type: string
18+
responses:
19+
'201':
20+
description: extra description 2

0 commit comments

Comments
 (0)