client-finder/scripts/test.ts

64 lines
2.9 KiB
TypeScript
Executable File

#!/usr/bin/env bun
import { runClientFinder } from '../src/index.js';
/**
* Run basic tests
*/
async function runTests(): Promise<void> {
console.log('Running client-finder tests...\n');
// Test 1: Dry run with query
console.log('Test 1: Dry run with query');
const result1 = await runClientFinder('office machine', 'us', true);
console.log('Result:', JSON.stringify(result1, null, 2));
if (result1.status !== 'success') throw new Error('Test 1 failed: status should be success');
if (result1.workflowStatus !== 'dry_run') throw new Error('Test 1 failed: workflowStatus should be dry_run');
console.log('✓ Test 1 passed\n');
// Test 2: Missing query
console.log('Test 2: Missing query');
const result2 = await runClientFinder('', 'us', true);
console.log('Result:', JSON.stringify(result2, null, 2));
if (result2.status !== 'failed') throw new Error('Test 2 failed: status should be failed');
if (result2.error !== 'missing query argument') throw new Error('Test 2 failed: error message mismatch');
console.log('✓ Test 2 passed\n');
// Test 3: Query with country
console.log('Test 3: Query with country');
const result3 = await runClientFinder('coffee shop', 'us', true);
console.log('Result:', JSON.stringify(result3, null, 2));
if (result3.status !== 'success') throw new Error('Test 3 failed: status should be success');
if (result3.primaryQuery === '') throw new Error('Test 3 failed: primaryQuery should not be empty');
if (result3.expandedQueries.length === 0) throw new Error('Test 3 failed: expandedQueries should not be empty');
console.log('✓ Test 3 passed\n');
// Test 4: Cold-outreach prefix normalization
console.log('Test 4: Cold-outreach prefix normalization');
const result4 = await runClientFinder('cold-outreach: office machine', 'us', true);
console.log('Result:', JSON.stringify(result4, null, 2));
if (result4.status !== 'success') throw new Error('Test 4 failed: status should be success');
if (result4.inputQuery.includes('cold-outreach:')) throw new Error('Test 4 failed: prefix should be removed');
console.log('✓ Test 4 passed\n');
// Test 5: LLM expansion (simulate with env)
console.log('Test 5: LLM expansion');
const llmJson = JSON.stringify({
expandedQueries: ['test query us', 'test query supplier us'],
primaryQuery: 'test query us',
});
console.log('Setting QUERY_EXPANSION_JSON:', llmJson);
process.env.QUERY_EXPANSION_JSON = llmJson;
const result5 = await runClientFinder('test query', 'us', true);
console.log('Result:', JSON.stringify(result5, null, 2));
if (result5.status !== 'success') throw new Error('Test 5 failed: status should be success');
if (result5.expansionSource !== 'llm') throw new Error(`Test 5 failed: expansionSource should be llm, got ${result5.expansionSource}`);
console.log('✓ Test 5 passed\n');
console.log('All tests passed! ✓');
}
runTests().catch((error) => {
console.error('Test failed:', error);
process.exit(1);
});