diff --git a/packages/bruno-electron/src/store/global-environments.js b/packages/bruno-electron/src/store/global-environments.js index 8a88674ef..57367fd23 100644 --- a/packages/bruno-electron/src/store/global-environments.js +++ b/packages/bruno-electron/src/store/global-environments.js @@ -41,6 +41,18 @@ class GlobalEnvironmentsStore { getGlobalEnvironments() { let globalEnvironments = this.store.get('environments', []); globalEnvironments = this.decryptGlobalEnvironmentVariables({ globalEnvironments }); + + // Previously, a bug caused environment variables to be saved without a type. + // Since that issue is now fixed, this code ensures that anyone who imported + // data before the fix will have the missing types added retroactively. + globalEnvironments?.forEach(env => { + env?.variables?.forEach(v => { + if (!v.type) { + v.type = 'text'; + } + }); + }); + return globalEnvironments; } diff --git a/packages/bruno-electron/tests/store/global-environments.test.js b/packages/bruno-electron/tests/store/global-environments.test.js new file mode 100644 index 000000000..41c59ef51 --- /dev/null +++ b/packages/bruno-electron/tests/store/global-environments.test.js @@ -0,0 +1,54 @@ +const { globalEnvironmentsStore } = require('../../src/store/global-environments'); + +// Previously, a bug caused environment variables to be saved without a type. +// Since that issue is now fixed, this code ensures that anyone who imported +// data before the fix will have the missing types added retroactively. +describe('global environment variable type backward compatibility', () => { + beforeEach(() => { + globalEnvironmentsStore.store.clear(); + }); + + it('should add type field for existing global environments without type', () => { + // Mock global environments without type field + const mockGlobalEnvironments = [ + { + uid: "env-1", + name: "Test Environment", + variables: [ + { + uid: "var-1", + name: "regular_var", + value: "regular_value", + enabled: true, + secret: false + // Missing: type field + }, + { + uid: "var-2", + name: "secret_var", + value: "secret_value", + enabled: true, + secret: true + // Missing: type field + } + ] + } + ]; + + globalEnvironmentsStore.store.set('environments', mockGlobalEnvironments); + + const processedEnvironments = globalEnvironmentsStore.getGlobalEnvironments(); + + expect(processedEnvironments).toHaveLength(1); + expect(processedEnvironments[0].variables).toHaveLength(2); + + const regularVar = processedEnvironments[0].variables.find(v => v.name === 'regular_var'); + const secretVar = processedEnvironments[0].variables.find(v => v.name === 'secret_var'); + + expect(regularVar.name).toBe('regular_var'); + expect(regularVar.type).toBe('text'); + + expect(secretVar.name).toBe('secret_var'); + expect(secretVar.type).toBe('text'); + }); +});