Skip to content

Commit d47b436

Browse files
author
Iurii Golovinskii
committed
fixed tests
1 parent 3388550 commit d47b436

File tree

8 files changed

+45
-36
lines changed

8 files changed

+45
-36
lines changed

test/apiKinds.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ describe('Semi-breaking changes for no-bwc operations test', () => {
145145
}, {}, portal)
146146

147147
const result = await editor.run()
148-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
149-
// @ts-ignore
150-
expect(result.comparisons[0].operationTypes[0].changesSummary?.[SEMI_BREAKING_CHANGE_TYPE]).toBe(3)
148+
149+
expect(result.comparisons[0].operationTypes[0].changesSummary?.[RISKY_CHANGE_TYPE]).toBe(3)
151150
})
152151

153152
test('should have 1 breaking change', async () => {

test/declarative-changes-in-rest-package-version.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ describe('Number of declarative changes in rest package version test', () => {
5656
const result = await buildChangelogPackage('declarative-changes-in-rest-package-version/case5')
5757
expect(result).toEqual(changesSummaryMatcher({
5858
[BREAKING_CHANGE_TYPE]: 1,
59-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
59+
[RISKY_CHANGE_TYPE]: 1,
6060
}))
6161
expect(result).toEqual(numberOfImpactedOperationsMatcher({
6262
[BREAKING_CHANGE_TYPE]: 1,
63-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
63+
[RISKY_CHANGE_TYPE]: 1,
6464
}))
6565
})
6666
})

test/deprecated.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('Deprecated Items test', () => {
9191
const result = await editor.run()
9292
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
9393
// @ts-ignore
94-
expect(result.comparisons[0].operationTypes[0].changesSummary?.[SEMI_BREAKING_CHANGE_TYPE]).toBe(1)
94+
expect(result.comparisons[0].operationTypes[0].changesSummary?.[RISKY_CHANGE_TYPE]).toBe(1)
9595
expect(result.comparisons[0].operationTypes[0].changesSummary?.[BREAKING_CHANGE_TYPE]).toBe(0)
9696
})
9797

@@ -107,6 +107,6 @@ describe('Deprecated Items test', () => {
107107
const result = await editor.run()
108108
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
109109
// @ts-ignore
110-
expect(result.comparisons[0].operationTypes[0].changesSummary?.[SEMI_BREAKING_CHANGE_TYPE]).toBe(4)
110+
expect(result.comparisons[0].operationTypes[0].changesSummary?.[RISKY_CHANGE_TYPE]).toBe(4)
111111
})
112112
})

test/graphql.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('GraphQL test', () => {
5757
],
5858
})
5959

60-
const changes = result.comparisons[0].data?.flatMap(data => data.changes)
60+
const changes = result.comparisons[0].data?.flatMap(data => data.diffs)
6161

6262
expect(changes?.length).toBeTruthy()
6363
expect(changes?.every(change => change?.description)).toBeTruthy()

test/helpers/matchers.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import {
1818
ChangeMessage,
1919
ChangeSummary,
20-
ChangeSummaryDto,
2120
DeprecateItem,
22-
EMPTY_CHANGE_SUMMARY_DTO,
21+
EMPTY_CHANGE_SUMMARY,
2322
OperationChanges,
2423
type OperationsApiType,
2524
OperationType,
@@ -56,26 +55,26 @@ export function apihubOperationChangesMatcher(
5655
}
5756

5857
export function changesSummaryMatcher(
59-
expected: Partial<ChangeSummaryDto>,
58+
expected: Partial<ChangeSummary>,
6059
apiType: OperationsApiType = REST_API_TYPE,
6160
): ApihubChangesSummaryMatcher {
6261
return operationTypeMatcher({
6362
apiType: apiType,
6463
changesSummary: expect.objectContaining({
65-
...EMPTY_CHANGE_SUMMARY_DTO,
64+
...EMPTY_CHANGE_SUMMARY,
6665
...expected,
6766
}),
6867
})
6968
}
7069

7170
export function numberOfImpactedOperationsMatcher(
72-
expected: Partial<ChangeSummaryDto>,
71+
expected: Partial<ChangeSummary>,
7372
apiType: OperationsApiType = REST_API_TYPE,
7473
): ApihubChangesSummaryMatcher {
7574
return operationTypeMatcher({
7675
apiType: apiType,
7776
numberOfImpactedOperations: expect.objectContaining({
78-
...EMPTY_CHANGE_SUMMARY_DTO,
77+
...EMPTY_CHANGE_SUMMARY,
7978
...expected,
8079
}),
8180
})

test/helpers/registry/apihub.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
BuilderContext,
2323
BuilderResolvers,
2424
BuildResult,
25-
graphqlApiBuilder,
25+
graphqlApiBuilder, MESSAGE_SEVERITY,
2626
OperationId,
2727
OperationsApiType,
2828
PackageId,
@@ -51,6 +51,7 @@ import {
5151
saveNotifications,
5252
saveOperationsArray,
5353
} from './utils'
54+
import { toVersionsComparisonDto } from '../../../src/utils/transformToDto'
5455

5556
export const VERSIONS_PATH = 'test/versions'
5657

@@ -106,6 +107,14 @@ export class ApihubRegistry implements IRegistry {
106107
} catch (e) {
107108
// do nothing
108109
}
110+
111+
const logError = (message: string): void => {
112+
notifications.push({
113+
severity: MESSAGE_SEVERITY.Error,
114+
message: message,
115+
})
116+
}
117+
109118
await fs.mkdir(basePath, { recursive: true })
110119

111120
await saveInfo(config, basePath)
@@ -115,9 +124,9 @@ export class ApihubRegistry implements IRegistry {
115124

116125
await saveOperationsArray(operations, basePath)
117126
await saveEachOperation(operations, basePath)
118-
119-
await saveComparisonsArray(comparisons, basePath)
120-
await saveEachComparison(comparisons, basePath)
127+
const comparisonsDto = comparisons.map(comparison => toVersionsComparisonDto(comparison, logError))
128+
await saveComparisonsArray(comparisonsDto, basePath)
129+
await saveEachComparison(comparisonsDto, basePath)
121130
await saveNotifications(notifications, basePath)
122131
}
123132

test/helpers/registry/local.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
EMPTY_CHANGE_SUMMARY, EMPTY_CHANGE_SUMMARY_DTO,
2727
FILE_FORMAT,
2828
GRAPHQL_API_TYPE,
29-
graphqlApiBuilder,
29+
graphqlApiBuilder, MESSAGE_SEVERITY,
3030
NotificationMessage,
3131
OperationId,
3232
OperationsApiType,
@@ -71,6 +71,7 @@ import { getCompositeKey, getSplittedVersionKey, isNotEmpty, toBase64 } from '..
7171
import { groupBy } from 'graphql/jsutils/groupBy'
7272
import { IRegistry } from './types'
7373
import { calculateTotalChangeSummary } from '../../../src/components/compare'
74+
import { toVersionsComparisonDto } from '../../../src/utils/transformToDto'
7475

7576
const VERSIONS_PATH = 'test/versions'
7677
const DEFAULT_PROJECTS_PATH = 'test/projects'
@@ -366,8 +367,15 @@ export class LocalRegistry implements IRegistry {
366367
await saveOperationsArray(operations, basePath)
367368
await saveEachOperation(operations, basePath)
368369

369-
await saveComparisonsArray(comparisons, basePath)
370-
await saveEachComparison(comparisons, basePath)
370+
const logError = (message: string): void => {
371+
notifications.push({
372+
severity: MESSAGE_SEVERITY.Error,
373+
message: message,
374+
})
375+
}
376+
const comparisonsDto = comparisons.map(comparison => toVersionsComparisonDto(comparison, logError))
377+
await saveComparisonsArray(comparisonsDto, basePath)
378+
await saveEachComparison(comparisonsDto, basePath)
371379
await saveNotifications(notifications, basePath)
372380
}
373381

test/semi-breaking-changes.test.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
*/
1616

1717
import { changesSummaryMatcher, Editor, LocalRegistry, numberOfImpactedOperationsMatcher } from './helpers'
18-
import {
19-
BREAKING_CHANGE_TYPE,
20-
BUILD_TYPE,
21-
NON_BREAKING_CHANGE_TYPE,
22-
SEMI_BREAKING_CHANGE_TYPE,
23-
VERSION_STATUS,
24-
} from '../src'
18+
import { BREAKING_CHANGE_TYPE, BUILD_TYPE, NON_BREAKING_CHANGE_TYPE, RISKY_CHANGE_TYPE, VERSION_STATUS } from '../src'
2519

2620
const portal = new LocalRegistry('new-deprecated')
2721

@@ -62,13 +56,13 @@ describe('Semi-breaking changes test', () => {
6256
[NON_BREAKING_CHANGE_TYPE]: 1,
6357
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
6458
// @ts-ignore
65-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
59+
[RISKY_CHANGE_TYPE]: 1,
6660
}))
6761
expect(result).toEqual(numberOfImpactedOperationsMatcher({
6862
[NON_BREAKING_CHANGE_TYPE]: 1,
6963
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7064
// @ts-ignore
71-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
65+
[RISKY_CHANGE_TYPE]: 1,
7266
}))
7367
})
7468

@@ -108,13 +102,13 @@ describe('Semi-breaking changes test', () => {
108102
[BREAKING_CHANGE_TYPE]: 1,
109103
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
110104
// @ts-ignore
111-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
105+
[RISKY_CHANGE_TYPE]: 1,
112106
}))
113107
expect(result).toEqual(numberOfImpactedOperationsMatcher({
114108
[BREAKING_CHANGE_TYPE]: 1,
115109
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
116110
// @ts-ignore
117-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
111+
[RISKY_CHANGE_TYPE]: 1,
118112
}))
119113
})
120114

@@ -151,12 +145,12 @@ describe('Semi-breaking changes test', () => {
151145
expect(result).toEqual(changesSummaryMatcher({
152146
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
153147
// @ts-ignore
154-
[SEMI_BREAKING_CHANGE_TYPE]: 2,
148+
[RISKY_CHANGE_TYPE]: 2,
155149
}))
156150
expect(result).toEqual(numberOfImpactedOperationsMatcher({
157151
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
158152
// @ts-ignore
159-
[SEMI_BREAKING_CHANGE_TYPE]: 2,
153+
[RISKY_CHANGE_TYPE]: 2,
160154
}))
161155
})
162156

@@ -193,13 +187,13 @@ describe('Semi-breaking changes test', () => {
193187
expect(result).toEqual(changesSummaryMatcher({
194188
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
195189
// @ts-ignore
196-
[SEMI_BREAKING_CHANGE_TYPE]: 3,
190+
[RISKY_CHANGE_TYPE]: 3,
197191
[NON_BREAKING_CHANGE_TYPE]: 1,
198192
}))
199193
expect(result).toEqual(numberOfImpactedOperationsMatcher({
200194
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
201195
// @ts-ignore
202-
[SEMI_BREAKING_CHANGE_TYPE]: 1,
196+
[RISKY_CHANGE_TYPE]: 1,
203197
[NON_BREAKING_CHANGE_TYPE]: 1,
204198
}))
205199
})

0 commit comments

Comments
 (0)