mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-09-08 18:47:14 +00:00
feat(n8n-runner): support async response handling (#2487)
* feat(n8n-runner): support async response handling * fix(n8n-runner): expose response handling in form * fix(n8n-runner): preserve async response semantics --------- Co-authored-by: dadachann <185672915+dadachann@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import ts from 'typescript';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const sourcePath = path.resolve(
|
||||
currentDirectory,
|
||||
'../../src/app/home/components/dynamic-form/N8nAuthFieldVisibility.ts',
|
||||
);
|
||||
|
||||
function loadVisibilityPolicy() {
|
||||
const source = fs.readFileSync(sourcePath, 'utf8');
|
||||
const compiled = ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
||||
}).outputText;
|
||||
const loadedModule = { exports: {} };
|
||||
new Function('require', 'module', 'exports', compiled)(
|
||||
() => {
|
||||
throw new Error('N8nAuthFieldVisibility must not have runtime imports');
|
||||
},
|
||||
loadedModule,
|
||||
loadedModule.exports,
|
||||
);
|
||||
return loadedModule.exports;
|
||||
}
|
||||
|
||||
test('shows response handling with the other common n8n fields', () => {
|
||||
const { shouldShowN8nConfigField } = loadVisibilityPolicy();
|
||||
|
||||
for (const field of [
|
||||
'webhook-url',
|
||||
'auth-type',
|
||||
'timeout',
|
||||
'output-key',
|
||||
'response-handling',
|
||||
]) {
|
||||
assert.equal(shouldShowN8nConfigField(field, 'none'), true, field);
|
||||
}
|
||||
});
|
||||
|
||||
test('shows only fields for the selected n8n authentication method', () => {
|
||||
const { shouldShowN8nConfigField } = loadVisibilityPolicy();
|
||||
|
||||
assert.equal(shouldShowN8nConfigField('basic-username', 'basic'), true);
|
||||
assert.equal(shouldShowN8nConfigField('basic-password', 'jwt'), false);
|
||||
assert.equal(shouldShowN8nConfigField('jwt-secret', 'jwt'), true);
|
||||
assert.equal(shouldShowN8nConfigField('header-name', 'header'), true);
|
||||
assert.equal(shouldShowN8nConfigField('unrelated-field', 'none'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user