Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/bruno-api-docs/src/hooks/useVariableResolver.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,61 @@ describe('lookup (variable hover card)', () => {
expect(html).toContain('<span data-testid="scope">undefined</span>');
});
});

const NestedProbe: React.FC = () => {
const r = useResolvedVariables();
return (
<div>
<span data-testid="nested-resolve">{r.resolve('{{endpoint}}')}</span>
<span data-testid="nested-interpolate">{r.interpolate('{{endpoint}}')}</span>
</div>
);
};

describe('nested variable resolution', () => {
const nested = {
request: {
variables: [
{ name: 'endpoint', value: '{{host}}/v1' },
{ name: 'host', value: 'https://api.test' }
]
},
config: { environments: [{ name: 'Dev', variables: [] }] }
} as unknown as typeof collection;

it('follows a variable that points at another variable, for display and for interpolation', () => {
Comment thread
adwait-bruno marked this conversation as resolved.
const store = createOpenCollectionStore();
store.dispatch(setDocsCollection(nested));
store.dispatch(setActiveEnv('Dev'));
store.dispatch(setShowVars(true));

const html = renderToStaticMarkup(
<Provider store={store}>
<ItemVariableResolverProvider collection={nested} ancestry={[]} item={null} writable>
<NestedProbe />
</ItemVariableResolverProvider>
</Provider>
);

expect(html).toContain('<span data-testid="nested-resolve">https://api.test/v1</span>');
expect(html).toContain('<span data-testid="nested-interpolate">https://api.test/v1</span>');
});

it('gates resolve on showVars but never interpolate', () => {
const store = createOpenCollectionStore();
store.dispatch(setDocsCollection(nested));
store.dispatch(setActiveEnv('Dev'));
store.dispatch(setShowVars(false));

const html = renderToStaticMarkup(
<Provider store={store}>
<ItemVariableResolverProvider collection={nested} ancestry={[]} item={null} writable>
<NestedProbe />
</ItemVariableResolverProvider>
</Provider>
);

expect(html).toContain('<span data-testid="nested-resolve">{{endpoint}}</span>');
expect(html).toContain('<span data-testid="nested-interpolate">https://api.test/v1</span>');
});
});
6 changes: 3 additions & 3 deletions packages/bruno-api-docs/src/hooks/useVariableResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getItemUuid } from '@/utils/itemUtils';
import { mockDataFunctions, timeBasedDynamicVars } from '@/runner/utils/faker-functions';
import {
buildScopedVariableModel,
resolveVariables,
resolveValueDeep,
singleReferenceName,
detectSpecialScope,
isValidVariableName,
Expand Down Expand Up @@ -95,7 +95,7 @@ const makeResolver = (
activeEnvName: string | null
): VariableResolver => {
const isSecret = (name: string) => model.secretNames.has(name.trim());
const interpolate = (raw: string) => resolveVariables(raw, model.values);
const interpolate = (raw: string) => resolveValueDeep(raw, model.values);
return {
showVars,
activeEnvName,
Expand Down Expand Up @@ -263,7 +263,7 @@ export const ItemVariableResolverProvider: React.FC<{
);

const interpolateWithSecrets = useCallback(
(raw: string) => resolveVariables(raw, model.fullValues),
(raw: string) => resolveValueDeep(raw, model.fullValues),
[model]
);

Expand Down
Loading