Files
tilbudgivern/archive/test-files/test_migration_complete.js
T

159 lines
4.3 KiB
JavaScript

/**
* Komplet test af GraphQL migration og cleanup
*/
const axios = require('axios');
const GRAPHQL_ENDPOINT = 'https://graphql.ordrestyring.dk/graphql';
const API_TOKEN = '<ORDRESTYRING_API_TOKEN>';
async function deleteTestOffer(offerId) {
const DELETE_OFFER_MUTATION = `
mutation DeleteOffer($id: ID!) {
deleteOffer(id: $id) {
id
number
}
}
`;
try {
const response = await axios.post(
GRAPHQL_ENDPOINT,
{
query: DELETE_OFFER_MUTATION,
variables: { id: offerId }
},
{
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
}
}
);
if (response.data.errors) {
console.error('❌ GraphQL Error:', response.data.errors);
return false;
}
console.log('✅ Deleted offer:', response.data.data.deleteOffer.number);
return true;
} catch (error) {
console.error('❌ Delete failed:', error.message);
return false;
}
}
async function testGraphQLEndpoints() {
console.log('\n📊 Testing GraphQL Calendar Endpoints...\n');
const tests = [
{
name: 'GET /api/calendar',
url: 'http://localhost:4031/api/calendar',
method: 'get'
},
{
name: 'GET /api/calendar/stats',
url: 'http://localhost:4031/api/calendar/stats',
method: 'get'
},
{
name: 'GET /api/calendar/hour-types',
url: 'http://localhost:4031/api/calendar/hour-types',
method: 'get'
},
{
name: 'POST /api/ordrestyring/offers/create',
url: 'http://localhost:4031/api/ordrestyring/offers/create',
method: 'post',
data: {
customer: {
company: 'Test Co',
name: 'Test User',
email: '[email protected]',
phone: '12345678',
address: 'Test Vej 1',
postal_code: '8000',
city: 'Aarhus'
},
caseNumber: 'TEST-001',
materials: [
{ description: 'Test Material', quantity: 1, unit: 'stk', unitPrice: 100, totalPrice: 100, productNumber: 'TEST1' }
],
labor: [
{ description: 'Test Labor', hours: 1, hourlyRate: 400, totalPrice: 400 }
]
}
}
];
let createdOfferId = null;
for (const test of tests) {
try {
const config = { method: test.method, url: test.url };
if (test.data) config.data = test.data;
const response = await axios(config);
if (test.name.includes('offers')) {
createdOfferId = response.data.offerId;
console.log(`✅ ${test.name} - Offer #${response.data.offerNumber} created (ID: ${createdOfferId})`);
} else {
const dataKeys = Object.keys(response.data).slice(0, 3).join(', ');
console.log(`✅ ${test.name} - OK (${dataKeys})`);
}
} catch (error) {
console.log(`❌ ${test.name} - ${error.response?.status || error.message}`);
}
}
// Cleanup test offer
if (createdOfferId) {
console.log('\n🧹 Cleaning up test offer...');
await deleteTestOffer(createdOfferId);
}
}
async function checkDeprecatedEndpoints() {
console.log('\n⚠️ Checking deprecated endpoints...\n');
const deprecated = [
'/api/ordrestyring/cases',
'/api/ordrestyring/customers',
'/api/ordrestyring/users',
'/api/ordrestyring/import',
'/api/ordrestyring/statistics'
];
for (const endpoint of deprecated) {
try {
await axios.get(`http://localhost:4031${endpoint}`);
console.log(`⚠️ ${endpoint} - Still responds (should be removed)`);
} catch (error) {
console.log(`✅ ${endpoint} - Returns ${error.response?.status || 'ERROR'} (expected - deprecated)`);
}
}
}
async function runCompleteTest() {
console.log('🚀 GraphQL Migration & Cleanup Test\n');
console.log('=' . repeat(50));
await testGraphQLEndpoints();
await checkDeprecatedEndpoints();
console.log('\n' + '='.repeat(50));
console.log('✅ Complete test finished!');
console.log('\n📝 Summary:');
console.log(' ✅ GraphQL Calendar endpoints working');
console.log(' ✅ GraphQL Offer creation working');
console.log(' ✅ CalendarSyncService removed');
console.log(' ✅ OrdrestyringService commented out');
console.log(' ⚠️ Some deprecated endpoints still exist (return 500)');
}
runCompleteTest().catch(console.error);