Skip to content

Commit f3c208a

Browse files
fix: retrieve correct versions in session (#796)
* fix: update session versions * fix: get correct versions in the session --------- Co-authored-by: svcAPLBot <[email protected]>
1 parent a9ab90a commit f3c208a

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

src/otomi-stack.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,97 @@ describe('Users tests', () => {
753753
})
754754
})
755755

756+
describe('getVersions', () => {
757+
let otomiStack: OtomiStack
758+
759+
beforeEach(async () => {
760+
otomiStack = new OtomiStack()
761+
await otomiStack.init()
762+
})
763+
764+
afterEach(() => {
765+
jest.restoreAllMocks()
766+
})
767+
768+
test('should return versions with otomi version from settings', () => {
769+
const mockSettings = { otomi: { version: '1.2.3' } }
770+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
771+
772+
const result = (otomiStack as any).getVersions('abc123')
773+
774+
expect(result).toHaveProperty('core', '1.2.3')
775+
expect(result).toHaveProperty('api')
776+
expect(result).toHaveProperty('console')
777+
expect(result).toHaveProperty('values', 'abc123')
778+
expect(otomiStack.getSettings).toHaveBeenCalledWith(['otomi'])
779+
})
780+
781+
test('should fallback to env.VERSIONS.core when otomi.version is not available', () => {
782+
const mockSettings = { otomi: undefined }
783+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
784+
785+
const result = (otomiStack as any).getVersions('def456')
786+
787+
expect(result).toHaveProperty('core')
788+
expect(result).toHaveProperty('api')
789+
expect(result).toHaveProperty('console')
790+
expect(result).toHaveProperty('values', 'def456')
791+
})
792+
793+
test('should fallback to process.env.npm_package_version when env.VERSIONS.api is not available', () => {
794+
const originalNpmVersion = process.env.npm_package_version
795+
process.env.npm_package_version = '5.0.0'
796+
797+
const mockSettings = { otomi: { version: '1.2.3' } }
798+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
799+
800+
const result = (otomiStack as any).getVersions('ghi789')
801+
802+
expect(result).toHaveProperty('core', '1.2.3')
803+
expect(result).toHaveProperty('api')
804+
expect(result).toHaveProperty('console')
805+
expect(result).toHaveProperty('values', 'ghi789')
806+
807+
process.env.npm_package_version = originalNpmVersion
808+
})
809+
810+
test('should handle undefined otomi settings gracefully', () => {
811+
const mockSettings = {}
812+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
813+
814+
const result = (otomiStack as any).getVersions('xyz123')
815+
816+
expect(result).toHaveProperty('core')
817+
expect(result).toHaveProperty('api')
818+
expect(result).toHaveProperty('console')
819+
expect(result).toHaveProperty('values', 'xyz123')
820+
})
821+
822+
test('should pass through currentSha as values field', () => {
823+
const mockSettings = { otomi: { version: '1.0.0' } }
824+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
825+
826+
const testSha = 'unique-commit-sha-123'
827+
const result = (otomiStack as any).getVersions(testSha)
828+
829+
expect(result.values).toBe(testSha)
830+
expect(typeof result.values).toBe('string')
831+
})
832+
833+
test('should return all required version fields', () => {
834+
const mockSettings = { otomi: { version: '1.0.0' } }
835+
jest.spyOn(otomiStack, 'getSettings').mockReturnValue(mockSettings)
836+
837+
const result = (otomiStack as any).getVersions('test-sha')
838+
839+
expect(Object.keys(result).sort()).toEqual(['api', 'console', 'core', 'values'])
840+
expect(typeof result.core).toBe('string')
841+
expect(typeof result.api).toBe('string')
842+
expect(typeof result.console).toBe('string')
843+
expect(typeof result.values).toBe('string')
844+
})
845+
})
846+
756847
describe('PodService', () => {
757848
let otomiStack: OtomiStack
758849
let clientMock: {

src/otomi-stack.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,16 @@ export default class OtomiStack {
24652465
}
24662466
}
24672467

2468+
private getVersions(currentSha: string): Record<string, string> {
2469+
const { otomi } = this.getSettings(['otomi'])
2470+
return {
2471+
core: otomi?.version ?? env.VERSIONS.core,
2472+
api: env.VERSIONS.api ?? process.env.npm_package_version,
2473+
console: env.VERSIONS.console,
2474+
values: currentSha,
2475+
}
2476+
}
2477+
24682478
async getSession(user: k8sUser): Promise<Session> {
24692479
const rootStack = await getSessionStack()
24702480
const valuesSchema = await getValuesSchema()
@@ -2495,12 +2505,7 @@ export default class OtomiStack {
24952505
objStorageApps: env.OBJ_STORAGE_APPS,
24962506
objStorageRegions,
24972507
},
2498-
versions: {
2499-
core: env.VERSIONS.core,
2500-
api: env.VERSIONS.api ?? process.env.npm_package_version,
2501-
console: env.VERSIONS.console,
2502-
values: currentSha,
2503-
},
2508+
versions: this.getVersions(currentSha),
25042509
valuesSchema,
25052510
}
25062511
return data

0 commit comments

Comments
 (0)