Files
bruno/tests/interpolation/dynamic-variable/set-var-dynamic-variable.spec.ts
Pooja 5e6444b8b5 feat: Set JavaScript sandbox to safe mode by default for new collections (#4824)
* feat: Set JavaScript sandbox to safe mode by default for new collections

* rm: sandbox code in playwright test

* rm: safe mode code in var interpolation test

* rm: sandbox modal code

* fix

* fix

* fix

* fix

* improve

* improvement

* fix

* fix
2025-12-18 17:27:38 +05:30

47 lines
1.8 KiB
TypeScript

import { test, expect } from '../../../playwright';
import { closeAllCollections, openCollection, sendRequest } from '../../utils/page';
import { buildCommonLocators } from '../../utils/page/locators';
test.describe.serial('Dynamic Variable Interpolation', () => {
test.afterEach(async ({ pageWithUserData: page }) => {
await closeAllCollections(page);
});
test('Verifying if the bru.setVar method interpolates random generator functions properly', async ({ pageWithUserData: page }) => {
const locators = buildCommonLocators(page);
// Open collection and accept sandbox mode
await openCollection(page, 'dynamic-variable-interpolation');
// Navigate to the request
await locators.sidebar.request('set-var-dynamic-variable').click();
// Send the request
await sendRequest(page, 200);
// Verify response contains the title field and that it's not the literal interpolation string
const responsePane = page.locator('.response-pane');
// Check that the response contains a title field
await expect(responsePane).toContainText('"title":');
// Get the response body text to extract the actual title value
const responseBodyText = await responsePane.innerText();
// Extract the title value from the JSON response
const titleMatch = responseBodyText.match(/"title":\s*"([^"]+)"/) ?? [];
expect(titleMatch).toBeTruthy();
const actualTitle = titleMatch[1];
// Verify that the title is not the literal interpolation string
// This ensures that the randomFirstName function was properly interpolated
expect(actualTitle).not.toEqual('{{$randomFirstName}}');
// Additional verification: ensure the title is a string and not empty
expect(actualTitle).toBeDefined();
expect(typeof actualTitle).toBe('string');
expect(actualTitle.length).toBeGreaterThan(0);
});
});