Skip to content

Commit 22f243e

Browse files
committed
refactor: add test for outdated api-processor validation when building package changelog
1 parent 0b4dbdb commit 22f243e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/changes.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ import {
2727
ANNOTATION_CHANGE_TYPE,
2828
BREAKING_CHANGE_TYPE,
2929
BUILD_TYPE,
30+
PackageVersionBuilder,
3031
NON_BREAKING_CHANGE_TYPE,
3132
UNCLASSIFIED_CHANGE_TYPE,
3233
} from '../src'
34+
import { VERSION_STATUS } from '../src/consts'
35+
import { jest } from '@jest/globals'
3336

3437
let beforePackage: LocalRegistry
3538
let afterPackage: LocalRegistry
@@ -292,4 +295,42 @@ describe('Changelog build type', () => {
292295
]),
293296
}))
294297
})
298+
299+
test('Should fail changelog build if on of the versions was built using outdated api-processor version', async () => {
300+
const pckgId = 'changelog/add-operation'
301+
302+
await LocalRegistry.openPackage(pckgId).publish(pckgId, {
303+
version: 'v1',
304+
packageId: pckgId,
305+
files: [{ fileId: 'before.yaml' }],
306+
})
307+
308+
await LocalRegistry.openPackage(pckgId).publish(pckgId, {
309+
version: 'v2',
310+
packageId: pckgId,
311+
files: [{ fileId: 'after.yaml' }],
312+
})
313+
314+
const editor = new Editor(pckgId, {
315+
version: 'v2',
316+
packageId: pckgId,
317+
previousVersionPackageId: pckgId,
318+
previousVersion: 'v1',
319+
buildType: BUILD_TYPE.CHANGELOG,
320+
status: VERSION_STATUS.RELEASE,
321+
})
322+
323+
// Simulate that current version was built with an outdated api-processor
324+
// Mock the builder's versionResolver method (not the registry's)
325+
const originalVersionResolver = (editor.builder as PackageVersionBuilder).versionResolver.bind(editor.builder)
326+
jest.spyOn(editor.builder as PackageVersionBuilder, 'versionResolver').mockImplementation(async (version, packageId) => {
327+
const resolved = await originalVersionResolver(version, packageId)
328+
if (resolved && packageId === pckgId && version === 'v2') {
329+
return { ...resolved, apiProcessorVersion: '0.0.0' }
330+
}
331+
return resolved
332+
})
333+
334+
await expect(editor.run()).rejects.toThrow('Can\'t build the changelog if current version was built using an outdated api-processor.')
335+
}, 100000)
295336
})

0 commit comments

Comments
 (0)