stigmergy 1.2.0 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -18
- package/README.md +31 -211
- package/STIGMERGY.md +70 -61
- package/docs/MULTI_USER_WIKI_COLLABORATION_SYSTEM.md +523 -0
- package/docs/PROJECT_CONSTITUTION.md +433 -433
- package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
- package/docs/PROMPT_BASED_SKILLS_SYSTEM_DESIGN.md +458 -0
- package/docs/SKILL_IMPLEMENTATION_CONSTRAINTS_AND_ALIGNMENT.md +423 -0
- package/docs/TECHNICAL_FEASIBILITY_ANALYSIS.md +308 -0
- package/examples/calculator-example.js +72 -72
- package/examples/cline_usage_examples.md +364 -364
- package/examples/encryption-example.js +67 -67
- package/examples/json-parser-example.js +120 -120
- package/examples/json-validation-example.js +64 -64
- package/examples/multilingual-hook-demo.js +125 -0
- package/examples/rest-client-example.js +52 -52
- package/examples/rest_client_example.js +54 -54
- package/package.json +38 -20
- package/scripts/build.js +74 -74
- package/scripts/dependency-analyzer.js +101 -0
- package/scripts/generate-cli-docs.js +64 -0
- package/scripts/post-deployment-config.js +296 -296
- package/scripts/postuninstall.js +46 -0
- package/scripts/preinstall-check.js +173 -173
- package/scripts/preuninstall.js +75 -0
- package/scripts/publish.js +58 -268
- package/scripts/run-layered-tests.js +247 -0
- package/scripts/safe-install.js +139 -139
- package/scripts/simple-publish.js +57 -59
- package/src/adapters/claude/install_claude_integration.js +292 -0
- package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
- package/src/adapters/codex/install_codex_integration.js +395 -0
- package/src/adapters/copilot/install_copilot_integration.js +716 -0
- package/src/adapters/gemini/install_gemini_integration.js +304 -0
- package/src/adapters/iflow/install_iflow_integration.js +304 -0
- package/src/adapters/qoder/install_qoder_integration.js +1090 -0
- package/src/adapters/qwen/install_qwen_integration.js +285 -0
- package/src/cli/router.js +562 -39
- package/src/core/cache_cleaner.js +82 -59
- package/src/core/cli_help_analyzer.js +297 -291
- package/src/core/cli_parameter_handler.js +5 -0
- package/src/core/cli_tools.js +6 -6
- package/src/core/coordination/index.js +2 -2
- package/src/core/coordination/nodejs/AdapterManager.js +30 -17
- package/src/core/coordination/nodejs/CLCommunication.js +28 -20
- package/src/core/coordination/nodejs/CLIIntegrationManager.js +72 -36
- package/src/core/coordination/nodejs/HealthChecker.js +13 -14
- package/src/core/coordination/nodejs/HookDeploymentManager.js +325 -63
- package/src/core/coordination/nodejs/StatisticsCollector.js +6 -6
- package/src/core/coordination/nodejs/index.js +29 -11
- package/src/core/coordination/nodejs/utils/Logger.js +1 -1
- package/src/core/enhanced_installer.js +92 -69
- package/src/core/enhanced_uninstaller.js +73 -53
- package/src/core/installer.js +815 -294
- package/src/core/multilingual/language-pattern-manager.js +172 -0
- package/src/core/smart_router.js +141 -26
- package/src/core/upgrade_manager.js +91 -46
- package/src/data_structures.js +1 -1
- package/src/deploy.js +2 -2
- package/src/index.js +3 -3
- package/src/test/cli-availability-checker.js +194 -0
- package/src/test/test-environment.js +289 -0
- package/src/utils/helpers.js +2 -2
- package/src/utils.js +7 -1
- package/test/multilingual/hook-deployment.test.js +91 -0
- package/test/multilingual/language-pattern-manager.test.js +140 -0
- package/test/multilingual/system-test.js +85 -0
- package/test/cache-cleaner-implemented.test.js +0 -328
- package/test/cache-cleaner.test.js +0 -390
- package/test/calculator.test.js +0 -215
- package/test/collision-test.js +0 -26
- package/test/comprehensive-enhanced-features.test.js +0 -252
- package/test/comprehensive-execution-test.js +0 -428
- package/test/conflict-prevention-test.js +0 -95
- package/test/cross-cli-detection-test.js +0 -33
- package/test/csv-processing-test.js +0 -36
- package/test/deploy-hooks-test.js +0 -250
- package/test/e2e/claude-cli-test.js +0 -128
- package/test/e2e/collaboration-test.js +0 -75
- package/test/e2e/comprehensive-test.js +0 -431
- package/test/e2e/error-handling-test.js +0 -90
- package/test/e2e/individual-tool-test.js +0 -143
- package/test/e2e/other-cli-test.js +0 -130
- package/test/e2e/qoder-cli-test.js +0 -128
- package/test/e2e/run-e2e-tests.js +0 -73
- package/test/e2e/test-data.js +0 -88
- package/test/e2e/test-utils.js +0 -222
- package/test/encryption-simple-test.js +0 -110
- package/test/encryption.test.js +0 -129
- package/test/enhanced-main-alignment.test.js +0 -298
- package/test/enhanced-uninstaller-implemented.test.js +0 -271
- package/test/enhanced-uninstaller.test.js +0 -284
- package/test/error-handling-test.js +0 -341
- package/test/fibonacci.test.js +0 -178
- package/test/final-deploy-test.js +0 -221
- package/test/final-install-test.js +0 -226
- package/test/hash-table-demo.js +0 -33
- package/test/hash-table-test.js +0 -26
- package/test/hash_table_test.js +0 -114
- package/test/hook-system-integration-test.js +0 -307
- package/test/iflow-integration-test.js +0 -292
- package/test/improved-install-test.js +0 -362
- package/test/install-command-test.js +0 -370
- package/test/json-parser-test.js +0 -161
- package/test/json-validation-test.js +0 -164
- package/test/natural-language-skills-test.js +0 -320
- package/test/nl-integration-test.js +0 -179
- package/test/parameter-parsing-test.js +0 -143
- package/test/plugin-deployment-test.js +0 -316
- package/test/postinstall-test.js +0 -269
- package/test/python-plugins-test.js +0 -259
- package/test/real-test.js +0 -435
- package/test/remaining-adapters-test.js +0 -256
- package/test/rest-client-test.js +0 -56
- package/test/rest_client.test.js +0 -85
- package/test/safe-installation-cleaner.test.js +0 -343
- package/test/simple-iflow-hook-test.js +0 -137
- package/test/stigmergy-upgrade-test.js +0 -243
- package/test/system-compatibility-test.js +0 -467
- package/test/tdd-deploy-fix-test.js +0 -324
- package/test/tdd-fixes-test.js +0 -211
- package/test/third-party-skills-test.js +0 -321
- package/test/tool-selection-integration-test.js +0 -158
- package/test/unit/calculator-full.test.js +0 -191
- package/test/unit/calculator-simple.test.js +0 -96
- package/test/unit/calculator.test.js +0 -97
- package/test/unit/cli-scanner.test.js +0 -291
- package/test/unit/cli_parameter_handler.test.js +0 -116
- package/test/unit/cross-cli-executor.test.js +0 -399
- package/test/weather-processor.test.js +0 -104
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Remaining Adapters Test Suite
|
|
5
|
-
* Tests CodeBuddy, Codex, and Copilot adapters functionality
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { execSync, spawn } = require('child_process');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
|
|
12
|
-
// Test configuration
|
|
13
|
-
const TEST_TIMEOUT = 30000;
|
|
14
|
-
const PROJECT_ROOT = path.resolve(__dirname, '..');
|
|
15
|
-
|
|
16
|
-
console.log('🧪 Starting Remaining Adapters Test Suite...');
|
|
17
|
-
console.log('Testing CodeBuddy, Codex, and Copilot adapters...\n');
|
|
18
|
-
|
|
19
|
-
// Function to run a command and capture output
|
|
20
|
-
function runCommand(command, options = {}) {
|
|
21
|
-
try {
|
|
22
|
-
const result = execSync(command, {
|
|
23
|
-
cwd: PROJECT_ROOT,
|
|
24
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
25
|
-
...options
|
|
26
|
-
});
|
|
27
|
-
return { success: true, output: result.toString(), error: null };
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return {
|
|
30
|
-
success: false,
|
|
31
|
-
output: error.stdout ? error.stdout.toString() : '',
|
|
32
|
-
error: error.stderr ? error.stderr.toString() : error.message
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Test 1: Check if adapters can be imported
|
|
38
|
-
async function testAdapterImports() {
|
|
39
|
-
console.log('📋 Test 1: Adapter Imports');
|
|
40
|
-
|
|
41
|
-
const adapters = [
|
|
42
|
-
{ name: 'CodeBuddy', import: 'src/adapters/codebuddy/standalone_codebuddy_adapter.py' },
|
|
43
|
-
{ name: 'Codex', import: 'src/adapters/codex/standalone_codex_adapter.py' },
|
|
44
|
-
{ name: 'Copilot', import: 'src/adapters/copilot/standalone_copilot_adapter.py' }
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
let passed = 0;
|
|
48
|
-
let total = adapters.length;
|
|
49
|
-
|
|
50
|
-
for (const adapter of adapters) {
|
|
51
|
-
try {
|
|
52
|
-
// Check if file exists
|
|
53
|
-
const filePath = path.join(PROJECT_ROOT, adapter.import);
|
|
54
|
-
if (fs.existsSync(filePath)) {
|
|
55
|
-
console.log(` ✅ ${adapter.name} adapter file exists`);
|
|
56
|
-
passed++;
|
|
57
|
-
} else {
|
|
58
|
-
console.log(` ❌ ${adapter.name} adapter file not found: ${filePath}`);
|
|
59
|
-
}
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.log(` ❌ ${adapter.name} adapter check failed: ${error.message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
console.log(` Result: ${passed}/${total} passed\n`);
|
|
66
|
-
return passed === total;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Test 2: Check adapter registry
|
|
70
|
-
async function testAdapterRegistry() {
|
|
71
|
-
console.log('📋 Test 2: Adapter Registry');
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
// Create a simple Python script to test adapter retrieval
|
|
75
|
-
const testScript = `
|
|
76
|
-
import sys
|
|
77
|
-
sys.path.append('${PROJECT_ROOT.replace(/\\/g, '\\\\')}')
|
|
78
|
-
|
|
79
|
-
try:
|
|
80
|
-
from src.adapters import get_codebuddy_adapter, get_codex_adapter, get_cline_adapter
|
|
81
|
-
|
|
82
|
-
# Test CodeBuddy adapter
|
|
83
|
-
codebuddy = get_codebuddy_adapter()
|
|
84
|
-
print("CodeBuddy adapter:", "OK" if codebuddy else "FAIL")
|
|
85
|
-
|
|
86
|
-
# Test Codex adapter
|
|
87
|
-
codex = get_codex_adapter()
|
|
88
|
-
print("Codex adapter:", "OK" if codex else "FAIL")
|
|
89
|
-
|
|
90
|
-
# Test Cline adapter (as placeholder for Copilot)
|
|
91
|
-
cline = get_cline_adapter()
|
|
92
|
-
print("Cline/Copilot adapter:", "OK" if cline else "FAIL")
|
|
93
|
-
|
|
94
|
-
except Exception as e:
|
|
95
|
-
print("Import error:", str(e))
|
|
96
|
-
`;
|
|
97
|
-
|
|
98
|
-
const scriptPath = path.join(PROJECT_ROOT, 'temp_adapter_test.py');
|
|
99
|
-
fs.writeFileSync(scriptPath, testScript);
|
|
100
|
-
|
|
101
|
-
const result = runCommand(`python "${scriptPath}"`);
|
|
102
|
-
fs.unlinkSync(scriptPath);
|
|
103
|
-
|
|
104
|
-
if (result.success) {
|
|
105
|
-
console.log(' Adapter registry test output:');
|
|
106
|
-
console.log(result.output);
|
|
107
|
-
|
|
108
|
-
// Count successful adapters
|
|
109
|
-
const lines = result.output.split('\n');
|
|
110
|
-
const successCount = lines.filter(line => line.includes('OK')).length;
|
|
111
|
-
|
|
112
|
-
console.log(` Result: ${successCount}/3 adapters loaded successfully\n`);
|
|
113
|
-
return successCount >= 2; // Expect at least 2 to work
|
|
114
|
-
} else {
|
|
115
|
-
console.log(' ❌ Adapter registry test failed:', result.error);
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.log(' ❌ Adapter registry test error:', error.message);
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Test 3: Check adapter functionality
|
|
125
|
-
async function testAdapterFunctionality() {
|
|
126
|
-
console.log('📋 Test 3: Adapter Functionality');
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
// Create a Python script to test basic adapter functionality
|
|
130
|
-
const testScript = `
|
|
131
|
-
import sys
|
|
132
|
-
import asyncio
|
|
133
|
-
sys.path.append('${PROJECT_ROOT.replace(/\\/g, '\\\\')}')
|
|
134
|
-
|
|
135
|
-
async def test_adapters():
|
|
136
|
-
try:
|
|
137
|
-
from src.adapters import get_codebuddy_adapter, get_codex_adapter
|
|
138
|
-
|
|
139
|
-
# Test CodeBuddy adapter
|
|
140
|
-
print("Testing CodeBuddy adapter...")
|
|
141
|
-
codebuddy = get_codebuddy_adapter()
|
|
142
|
-
if codebuddy:
|
|
143
|
-
result = await codebuddy.execute_task("Test task for CodeBuddy")
|
|
144
|
-
stats = codebuddy.get_statistics()
|
|
145
|
-
print(f" CodeBuddy execution: {'OK' if result else 'FAIL'}")
|
|
146
|
-
print(f" CodeBuddy stats: {stats.get('cli_name', 'unknown')}")
|
|
147
|
-
else:
|
|
148
|
-
print(" CodeBuddy adapter not available")
|
|
149
|
-
|
|
150
|
-
# Test Codex adapter
|
|
151
|
-
print("Testing Codex adapter...")
|
|
152
|
-
codex = get_codex_adapter()
|
|
153
|
-
if codex:
|
|
154
|
-
result = await codex.execute_task("Test task for Codex")
|
|
155
|
-
stats = codex.get_statistics()
|
|
156
|
-
print(f" Codex execution: {'OK' if result else 'FAIL'}")
|
|
157
|
-
print(f" Codex stats: {stats.get('cli_name', 'unknown')}")
|
|
158
|
-
else:
|
|
159
|
-
print(" Codex adapter not available")
|
|
160
|
-
|
|
161
|
-
except Exception as e:
|
|
162
|
-
print("Functionality test error:", str(e))
|
|
163
|
-
|
|
164
|
-
# Run the async function
|
|
165
|
-
asyncio.run(test_adapters())
|
|
166
|
-
`;
|
|
167
|
-
|
|
168
|
-
const scriptPath = path.join(PROJECT_ROOT, 'temp_functionality_test.py');
|
|
169
|
-
fs.writeFileSync(scriptPath, testScript);
|
|
170
|
-
|
|
171
|
-
const result = runCommand(`python "${scriptPath}"`);
|
|
172
|
-
fs.unlinkSync(scriptPath);
|
|
173
|
-
|
|
174
|
-
if (result.success) {
|
|
175
|
-
console.log(' Adapter functionality test output:');
|
|
176
|
-
console.log(result.output);
|
|
177
|
-
console.log(' ✅ Adapter functionality test completed\n');
|
|
178
|
-
return true;
|
|
179
|
-
} else {
|
|
180
|
-
console.log(' ⚠️ Adapter functionality test had issues:', result.error);
|
|
181
|
-
// Don't fail the test completely as some adapters might not be fully configured
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.log(' ⚠️ Adapter functionality test error:', error.message);
|
|
186
|
-
return true; // Don't fail completely
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Test 4: Check CLI integration
|
|
191
|
-
async function testCLIIntegration() {
|
|
192
|
-
console.log('📋 Test 4: CLI Integration');
|
|
193
|
-
|
|
194
|
-
// Check if stigmergy CLI is available
|
|
195
|
-
const stigmergyCheck = runCommand('npm list stigmergy-cli', { timeout: 5000 });
|
|
196
|
-
|
|
197
|
-
if (stigmergyCheck.success || stigmergyCheck.output.includes('stigmergy')) {
|
|
198
|
-
console.log(' ✅ Stigmergy CLI is available');
|
|
199
|
-
} else {
|
|
200
|
-
console.log(' ℹ️ Stigmergy CLI not installed globally (this is OK for local testing)');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Check if main entry point exists
|
|
204
|
-
const mainPath = path.join(PROJECT_ROOT, 'src', 'main_english.js');
|
|
205
|
-
if (fs.existsSync(mainPath)) {
|
|
206
|
-
console.log(' ✅ Main entry point exists');
|
|
207
|
-
} else {
|
|
208
|
-
console.log(' ❌ Main entry point not found');
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
console.log(' ✅ CLI integration check completed\n');
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Main test runner
|
|
217
|
-
async function runAllTests() {
|
|
218
|
-
console.log('🚀 Running Remaining Adapters Test Suite...\n');
|
|
219
|
-
|
|
220
|
-
const startTime = Date.now();
|
|
221
|
-
|
|
222
|
-
// Run all tests
|
|
223
|
-
const results = [];
|
|
224
|
-
|
|
225
|
-
results.push(await testAdapterImports());
|
|
226
|
-
results.push(await testAdapterRegistry());
|
|
227
|
-
results.push(await testAdapterFunctionality());
|
|
228
|
-
results.push(await testCLIIntegration());
|
|
229
|
-
|
|
230
|
-
const endTime = Date.now();
|
|
231
|
-
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
|
232
|
-
|
|
233
|
-
// Calculate results
|
|
234
|
-
const passed = results.filter(r => r).length;
|
|
235
|
-
const total = results.length;
|
|
236
|
-
|
|
237
|
-
console.log(`\n🏁 Test Suite Completed in ${duration}s`);
|
|
238
|
-
console.log(`📊 Final Result: ${passed}/${total} test groups passed`);
|
|
239
|
-
|
|
240
|
-
if (passed === total) {
|
|
241
|
-
console.log('🎉 All tests passed! Remaining adapters are working correctly.');
|
|
242
|
-
process.exit(0);
|
|
243
|
-
} else if (passed >= total * 0.75) {
|
|
244
|
-
console.log('✅ Most tests passed! Remaining adapters are mostly functional.');
|
|
245
|
-
process.exit(0);
|
|
246
|
-
} else {
|
|
247
|
-
console.log('❌ Some tests failed. Please check the output above.');
|
|
248
|
-
process.exit(1);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Run the tests
|
|
253
|
-
runAllTests().catch(error => {
|
|
254
|
-
console.error('💥 Test suite crashed:', error);
|
|
255
|
-
process.exit(1);
|
|
256
|
-
});
|
package/test/rest-client-test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const { RESTClient } = require('../src/utils');
|
|
2
|
-
|
|
3
|
-
async function testRESTClient() {
|
|
4
|
-
console.log('Testing REST API Client...\n');
|
|
5
|
-
|
|
6
|
-
// Test with a public API
|
|
7
|
-
const client = new RESTClient('https://jsonplaceholder.typicode.com');
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
// Test GET request
|
|
11
|
-
console.log('1. Testing GET request...');
|
|
12
|
-
const getResponse = await client.get('/posts/1');
|
|
13
|
-
console.log('GET Response Status:', getResponse.status);
|
|
14
|
-
console.log('GET Response Data Title:', getResponse.data.title);
|
|
15
|
-
console.log('-------------------\n');
|
|
16
|
-
|
|
17
|
-
// Test POST request
|
|
18
|
-
console.log('2. Testing POST request...');
|
|
19
|
-
const postData = {
|
|
20
|
-
title: 'Test Post',
|
|
21
|
-
body: 'This is a test post',
|
|
22
|
-
userId: 1
|
|
23
|
-
};
|
|
24
|
-
const postResponse = await client.post('/posts', postData);
|
|
25
|
-
console.log('POST Response Status:', postResponse.status);
|
|
26
|
-
console.log('POST Response Data ID:', postResponse.data.id);
|
|
27
|
-
console.log('-------------------\n');
|
|
28
|
-
|
|
29
|
-
// Test PUT request
|
|
30
|
-
console.log('3. Testing PUT request...');
|
|
31
|
-
const putData = {
|
|
32
|
-
id: 1,
|
|
33
|
-
title: 'Updated Post',
|
|
34
|
-
body: 'This post has been updated',
|
|
35
|
-
userId: 1
|
|
36
|
-
};
|
|
37
|
-
const putResponse = await client.put('/posts/1', putData);
|
|
38
|
-
console.log('PUT Response Status:', putResponse.status);
|
|
39
|
-
console.log('PUT Response Data Title:', putResponse.data.title);
|
|
40
|
-
console.log('-------------------\n');
|
|
41
|
-
|
|
42
|
-
// Test DELETE request
|
|
43
|
-
console.log('4. Testing DELETE request...');
|
|
44
|
-
const deleteResponse = await client.delete('/posts/1');
|
|
45
|
-
console.log('DELETE Response Status:', deleteResponse.status);
|
|
46
|
-
console.log('DELETE Request completed successfully');
|
|
47
|
-
console.log('-------------------\n');
|
|
48
|
-
|
|
49
|
-
console.log('All tests passed!');
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error('Test failed:', error.message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Run the test
|
|
56
|
-
testRESTClient();
|
package/test/rest_client.test.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test for REST API Client
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const RestClient = require('../src/core/rest_client');
|
|
6
|
-
|
|
7
|
-
async function testRestClient() {
|
|
8
|
-
console.log('Testing REST Client...\n');
|
|
9
|
-
|
|
10
|
-
// Test 1: Basic GET request
|
|
11
|
-
try {
|
|
12
|
-
console.log('Test 1: Basic GET request to JSONPlaceholder');
|
|
13
|
-
const client = new RestClient('https://jsonplaceholder.typicode.com');
|
|
14
|
-
|
|
15
|
-
const response = await client.get('/posts/1');
|
|
16
|
-
console.log('Status:', response.status);
|
|
17
|
-
console.log('Data:', JSON.stringify(response.data, null, 2));
|
|
18
|
-
console.log('Success!\n');
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error('Test 1 failed:', error.message, '\n');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Test 2: POST request
|
|
24
|
-
try {
|
|
25
|
-
console.log('Test 2: POST request to JSONPlaceholder');
|
|
26
|
-
const client = new RestClient('https://jsonplaceholder.typicode.com');
|
|
27
|
-
|
|
28
|
-
const postData = {
|
|
29
|
-
title: 'Test Post',
|
|
30
|
-
body: 'This is a test post',
|
|
31
|
-
userId: 1
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const response = await client.post('/posts', postData);
|
|
35
|
-
console.log('Status:', response.status);
|
|
36
|
-
console.log('Data:', JSON.stringify(response.data, null, 2));
|
|
37
|
-
console.log('Success!\n');
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error('Test 2 failed:', error.message, '\n');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Test 3: With custom headers
|
|
43
|
-
try {
|
|
44
|
-
console.log('Test 3: GET request with custom headers');
|
|
45
|
-
const client = new RestClient('https://jsonplaceholder.typicode.com');
|
|
46
|
-
client.setDefaultHeaders({
|
|
47
|
-
'Custom-Header': 'test-value',
|
|
48
|
-
'X-Test-Header': 'another-test'
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const response = await client.get('/posts/2');
|
|
52
|
-
console.log('Status:', response.status);
|
|
53
|
-
console.log('Headers:', response.headers);
|
|
54
|
-
console.log('Success!\n');
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error('Test 3 failed:', error.message, '\n');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Test 4: With query parameters
|
|
60
|
-
try {
|
|
61
|
-
console.log('Test 4: GET request with query parameters');
|
|
62
|
-
const client = new RestClient('https://jsonplaceholder.typicode.com');
|
|
63
|
-
|
|
64
|
-
const response = await client.get('/posts', {
|
|
65
|
-
params: {
|
|
66
|
-
userId: 1,
|
|
67
|
-
_limit: 3
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
console.log('Status:', response.status);
|
|
71
|
-
console.log('Data count:', response.data.length);
|
|
72
|
-
console.log('Success!\n');
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error('Test 4 failed:', error.message, '\n');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log('REST Client tests completed.');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Run tests if this file is executed directly
|
|
81
|
-
if (require.main === module) {
|
|
82
|
-
testRestClient();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = testRestClient;
|