rename nodejs package configurations
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { buildRequestContent, getRequestConfigForFile, mergeRequestConfig } from './generate-http-requests.js';
|
||||
|
||||
test('does not inherit parent auth when a child config has no auth override', () => {
|
||||
const parentAuth = { type: 'bearer', token: 'parent-token' };
|
||||
const merged = mergeRequestConfig({ auth: parentAuth }, {});
|
||||
|
||||
assert.equal(merged.auth, undefined);
|
||||
});
|
||||
|
||||
test('uses an explicit child auth object instead of inheriting the parent auth', () => {
|
||||
const parentAuth = { type: 'bearer', token: 'parent-token' };
|
||||
const childAuth = { type: 'basic', username: 'user', password: 'pass' };
|
||||
const merged = mergeRequestConfig({ auth: parentAuth }, { auth: childAuth });
|
||||
|
||||
assert.deepEqual(merged.auth, childAuth);
|
||||
});
|
||||
|
||||
test('reads auth inherit from a Bruno-style http block', () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'bruno-auth-'));
|
||||
const childDir = path.join(tempRoot, 'nested');
|
||||
fs.mkdirSync(childDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(tempRoot, 'opencollection.yml'), `request:\n auth:\n type: bearer\n token: "parent-token"\n`);
|
||||
fs.writeFileSync(path.join(tempRoot, 'folder.yml'), 'auth: inherit\n');
|
||||
fs.writeFileSync(path.join(childDir, 'request.yml'), 'http:\n auth: inherit\n');
|
||||
|
||||
const config = getRequestConfigForFile(path.join(childDir, 'request.yml'), tempRoot);
|
||||
|
||||
assert.deepEqual(config.auth, { type: 'bearer', token: 'parent-token' });
|
||||
});
|
||||
|
||||
test('renders dotenv placeholders in generated variable definitions', () => {
|
||||
const request = {
|
||||
url: 'https://example.test',
|
||||
params: [
|
||||
{ name: 'username', value: '{{elixFormsApiUsername}}', type: 'path' },
|
||||
],
|
||||
};
|
||||
|
||||
const output = buildRequestContent(request, 'Logout', {}, new Set(['elixFormsApiUsername']));
|
||||
|
||||
assert.match(output, /@username = "\{\{\$dotenv elixFormsApiUsername\}\}"/);
|
||||
});
|
||||
Reference in New Issue
Block a user