mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-29 15:44:13 +00:00
fix: Handle deleted environment variables in UI (#6703)
* fix: enhance environment variable management in collections slice * test: refactor deleteEnvVar test
This commit is contained in:
@@ -334,6 +334,9 @@ export const collectionsSlice = createSlice({
|
||||
const activeEnvironment = findEnvironmentInCollection(collection, activeEnvironmentUid);
|
||||
|
||||
if (activeEnvironment) {
|
||||
const existingEnvVarNames = new Set(Object.keys(envVariables));
|
||||
|
||||
// Update or add variables that exist in envVariables
|
||||
forOwn(envVariables, (value, key) => {
|
||||
const variable = find(activeEnvironment.variables, (v) => v.name === key);
|
||||
const isPersistent = persistentEnvVariables && persistentEnvVariables[key] !== undefined;
|
||||
@@ -369,6 +372,26 @@ export const collectionsSlice = createSlice({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle variables that were deleted via bru.deleteEnvVar()
|
||||
activeEnvironment.variables = activeEnvironment.variables.filter((variable) => {
|
||||
// Variable still exists in envVariables after script execution - keep it
|
||||
if (existingEnvVarNames.has(variable.name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Variable was deleted via bru.deleteEnvVar() - handle based on its state
|
||||
// If variable was modified by script (has persistedValue), restore original value
|
||||
if (variable.persistedValue !== undefined) {
|
||||
variable.value = variable.persistedValue;
|
||||
variable.ephemeral = false;
|
||||
delete variable.persistedValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove variable: either ephemeral (created by scripts) or non-ephemeral deleted via API
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
collection.runtimeVariables = runtimeVariables;
|
||||
|
||||
31
tests/environments/api-deleteEnvVar/api-deleteEnvVar.spec.ts
Normal file
31
tests/environments/api-deleteEnvVar/api-deleteEnvVar.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { test, expect } from '../../../playwright';
|
||||
import { sendRequest, openRequest, selectEnvironment, openEnvironmentSelector, closeEnvironmentPanel, closeAllCollections } from '../../utils/page';
|
||||
|
||||
test.describe.serial('bru.deleteEnvVar(name)', () => {
|
||||
test('should remove ephemeral variable from UI after deletion', async ({ pageWithUserData: page }) => {
|
||||
await test.step('Open request and select environment', async () => {
|
||||
await openRequest(page, 'collection', 'api-deleteEnvVar');
|
||||
await selectEnvironment(page, 'Stage');
|
||||
});
|
||||
|
||||
await test.step('Send request to set and delete variable', async () => {
|
||||
await sendRequest(page, 200);
|
||||
});
|
||||
|
||||
await test.step('Verify variable is removed from UI', async () => {
|
||||
await openEnvironmentSelector(page, 'collection');
|
||||
await page.getByText('Configure', { exact: true }).click();
|
||||
|
||||
const envTab = page.locator('.request-tab').filter({ hasText: 'Environments' });
|
||||
await expect(envTab).toBeVisible();
|
||||
|
||||
await expect(page.getByRole('row', { name: 'host' })).toBeVisible();
|
||||
await expect(page.getByRole('row', { name: 'tempToken' })).not.toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Cleanup', async () => {
|
||||
await closeEnvironmentPanel(page, 'collection');
|
||||
await closeAllCollections(page);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
meta {
|
||||
name: api-deleteEnvVar
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setEnvVar("tempToken", "abc123");
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.deleteEnvVar("tempToken");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "collection",
|
||||
"type": "collection"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{projectRoot}}/tests/environments/api-deleteEnvVar/fixtures/collection",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"maximized": false,
|
||||
"lastOpenedCollections": [
|
||||
"{{projectRoot}}/tests/environments/api-deleteEnvVar/fixtures/collection"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user