AutoCadServer/test-client.js
2025-05-16 18:17:54 +04:00

63 lines
1.8 KiB
JavaScript

const fetch = require('node-fetch');
// Simulate sending AutoCAD events to our server
async function sendTestEvent() {
try {
// Sample data for an Added event
const addedEvent = {
EventType: "Added",
ObjectId: "A1B2C3D4",
ObjectType: "Line",
Position: { X: 100.5, Y: 200.8, Z: 0.0 },
Timestamp: new Date().toISOString()
};
// Send to server
console.log('Sending test data to server...');
const response = await fetch('http://localhost:3000/api/autocad-events', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(addedEvent),
});
const data = await response.json();
console.log('Server response:', data);
// Sample data for a Modified event
const modifiedEvent = {
EventType: "Modified",
ObjectId: "A1B2C3D4",
ObjectType: "Line",
OldPosition: { X: 100.5, Y: 200.8, Z: 0.0 },
NewPosition: { X: 150.2, Y: 250.3, Z: 0.0 },
Timestamp: new Date().toISOString()
};
// Send to server
console.log('Sending modification test data to server...');
const modResponse = await fetch('http://localhost:3000/api/autocad-events', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(modifiedEvent),
});
const modData = await modResponse.json();
console.log('Server response:', modData);
// Retrieve all events
console.log('Retrieving all events from server...');
const getResponse = await fetch('http://localhost:3000/api/autocad-events');
const allEvents = await getResponse.json();
console.log('All stored events:', JSON.stringify(allEvents, null, 2));
} catch (error) {
console.error('Error sending test data:', error);
}
}
// Run the test
sendTestEvent();