Spaces:
Running
Running
File size: 4,278 Bytes
3ed6d7f 66097e1 3ed6d7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
// test-api.js - Test script to verify the API is working
// Run this with: node test-api.js
const API_URL = process.env.REUBENOS_URL || 'https://mcp-1st-birthday-reuben-os.hf.space';
async function testAPI() {
const sessionId = 'session_1763722877048_527d6bb8b7473568';
console.log('π Testing Reuben OS API...\n');
console.log(`API URL: ${API_URL}`);
console.log(`Session ID: ${sessionId}\n`);
try {
// Test 1: Save a regular file
console.log('π Test 1: Saving a regular file...');
const saveResponse = await fetch(`${API_URL}/api/mcp-handler`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: sessionId,
action: 'save_file',
fileName: 'test.txt',
content: 'This is a test file created at ' + new Date().toISOString()
})
});
const saveData = await saveResponse.json();
console.log('Save response:', saveData);
console.log('β
File save:', saveData.success ? 'SUCCESS' : 'FAILED');
console.log('');
// Test 2: Deploy a quiz
console.log('π― Test 2: Deploying a quiz...');
const quizData = {
title: 'Test Quiz',
description: 'A simple test quiz',
questions: [
{
id: 'q1',
question: 'Is this working?',
type: 'true-false',
correctAnswer: true,
points: 1
}
]
};
const quizResponse = await fetch(`${API_URL}/api/mcp-handler`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: sessionId,
action: 'deploy_quiz',
fileName: 'quiz.json',
content: JSON.stringify(quizData, null, 2)
})
});
const quizResponseData = await quizResponse.json();
console.log('Quiz response:', quizResponseData);
console.log('β
Quiz deploy:', quizResponseData.success ? 'SUCCESS' : 'FAILED');
console.log('');
// Test 3: Retrieve files
console.log('π Test 3: Retrieving files for session...');
const getResponse = await fetch(`${API_URL}/api/mcp-handler?sessionId=${sessionId}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
});
const getData = await getResponse.json();
console.log('Retrieve response:', {
success: getData.success,
fileCount: getData.count,
files: getData.files?.map(f => ({
name: f.name,
size: f.size,
isQuiz: f.isQuiz
}))
});
console.log('β
File retrieval:', getData.success ? 'SUCCESS' : 'FAILED');
if (getData.success && getData.files) {
console.log('\nπ Files found:');
getData.files.forEach(file => {
console.log(` - ${file.name} (${file.size} bytes)${file.isQuiz ? ' [QUIZ]' : ''}`);
if (file.name === 'quiz.json' && file.content) {
console.log(' Quiz content preview:', file.content.substring(0, 100) + '...');
}
});
}
// Test 4: Save to public folder
console.log('\nπ’ Test 4: Saving to public folder...');
const publicResponse = await fetch(`${API_URL}/api/mcp-handler`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: sessionId,
action: 'save_public',
fileName: 'public_test.txt',
content: 'This is a public file'
})
});
const publicData = await publicResponse.json();
console.log('Public save response:', publicData);
console.log('β
Public save:', publicData.success ? 'SUCCESS' : 'FAILED');
// Summary
console.log('\n' + '='.repeat(50));
console.log('π TEST SUMMARY:');
console.log(` Session ID: ${sessionId}`);
console.log(` Files in session: ${getData.count || 0}`);
console.log(` Quiz detected: ${getData.files?.some(f => f.isQuiz) ? 'YES' : 'NO'}`);
console.log('='.repeat(50));
} catch (error) {
console.error('β Test failed with error:', error);
console.error('\nMake sure:');
console.error('1. Your Next.js server is running (npm run dev)');
console.error('2. The API endpoint is accessible');
console.error('3. The /tmp directory is writable');
}
}
// Run the test
testAPI(); |