Skip to content

Commit 0b4dbdb

Browse files
committed
refactore: add outdated api-processor test for dashboard changelog built
1 parent dc63c1a commit 0b4dbdb

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/dashboards.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { describe, test, expect, jest } from '@jest/globals'
1717
import { LocalRegistry } from './helpers/registry'
1818
import { BUILD_TYPE, VERSION_STATUS } from '../src/consts'
1919
import { Editor } from './helpers/editor'
20+
import { PackageVersionBuilder } from '../src'
2021

2122
describe('Dashboard build', () => {
2223
test('dashboard should have changes', async () => {
@@ -96,4 +97,76 @@ describe('Dashboard build', () => {
9697
expect(args[1]).toBeTruthy() // packageId should not be empty
9798
})
9899
}, 100000)
100+
101+
test('Should fail changelog build if one of the packages was built using outdated api-processor version', async () => {
102+
const pckg1Id = 'dashboards/pckg1'
103+
const pckg2Id = 'dashboards/pckg2'
104+
105+
await LocalRegistry.openPackage(pckg1Id).publish(pckg1Id, {
106+
version: 'v1',
107+
packageId: pckg1Id,
108+
files: [{ fileId: 'v1.yaml' }],
109+
})
110+
111+
await LocalRegistry.openPackage(pckg1Id).publish(pckg1Id, {
112+
version: 'v2',
113+
packageId: pckg1Id,
114+
files: [{ fileId: 'v1.yaml' }],
115+
})
116+
117+
await LocalRegistry.openPackage(pckg2Id).publish(pckg2Id, {
118+
version: 'v1',
119+
packageId: pckg2Id,
120+
files: [{ fileId: 'v2.yaml' }],
121+
})
122+
123+
await LocalRegistry.openPackage(pckg2Id).publish(pckg2Id, {
124+
version: 'v2',
125+
packageId: pckg2Id,
126+
files: [{ fileId: 'v2.yaml' }],
127+
})
128+
129+
const dashboard = LocalRegistry.openPackage('dashboards/dashboard')
130+
await dashboard.publish(dashboard.packageId, {
131+
packageId: 'dashboards/dashboard',
132+
version: 'v1',
133+
apiType: 'rest',
134+
refs: [
135+
{ refId: pckg1Id, version: 'v1' },
136+
{ refId: pckg2Id, version: 'v1' },
137+
],
138+
})
139+
140+
await dashboard.publish(dashboard.packageId, {
141+
packageId: 'dashboards/dashboard',
142+
version: 'v2',
143+
apiType: 'rest',
144+
refs: [
145+
{ refId: pckg1Id, version: 'v2' },
146+
{ refId: pckg2Id, version: 'v2' },
147+
],
148+
})
149+
150+
const editor = new Editor(dashboard.packageId, {
151+
version: 'v2',
152+
packageId: dashboard.packageId,
153+
previousVersionPackageId: dashboard.packageId,
154+
previousVersion: 'v1',
155+
buildType: BUILD_TYPE.CHANGELOG,
156+
status: VERSION_STATUS.RELEASE,
157+
})
158+
159+
// Simulate that previous dashboard version was built with an outdated api-processor
160+
// Mock the builder's versionResolver method (not the registry's)
161+
const originalVersionResolver = (editor.builder as PackageVersionBuilder).versionResolver.bind(editor.builder)
162+
jest.spyOn(editor.builder as PackageVersionBuilder, 'versionResolver').mockImplementation(async (version, packageId) => {
163+
const resolved = await originalVersionResolver(version, packageId)
164+
if (resolved && packageId === pckg1Id && version === 'v1') {
165+
return { ...resolved, apiProcessorVersion: '0.0.0' }
166+
}
167+
return resolved
168+
})
169+
170+
await expect(editor.run()).rejects.toThrow('Can\'t build the changelog if previous version was built using an outdated api-processor.')
171+
}, 100000)
99172
})

0 commit comments

Comments
 (0)