57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
/**
|
|
* Smoke test script for Graph API connectivity
|
|
* Tests token acquisition and basic fetch from Microsoft Graph
|
|
*
|
|
* Usage: tsx scripts/test-graph-connection.ts
|
|
*/
|
|
|
|
import 'dotenv/config';
|
|
import { getGraphAccessToken } from '../worker/jobs/graphAuth';
|
|
import { fetchFromGraph } from '../worker/jobs/graphFetch';
|
|
|
|
async function main() {
|
|
console.log('=== Graph API Smoke Test ===\n');
|
|
|
|
// Check required env vars
|
|
const required = ['AZURE_AD_TENANT_ID', 'AZURE_AD_CLIENT_ID', 'AZURE_AD_CLIENT_SECRET'];
|
|
const missing = required.filter(key => !process.env[key]);
|
|
|
|
if (missing.length > 0) {
|
|
console.error('❌ Missing required environment variables:', missing.join(', '));
|
|
console.error('\nPlease set these in your .env file:');
|
|
missing.forEach(key => console.error(` ${key}=your_value_here`));
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
// Test 1: Token acquisition
|
|
console.log('Test 1: Acquiring Graph access token...');
|
|
const token = await getGraphAccessToken();
|
|
console.log('✓ Token acquired successfully (length:', token.length, 'chars)\n');
|
|
|
|
// Test 2: Fetch device configurations
|
|
console.log('Test 2: Fetching device configurations...');
|
|
const configs = await fetchFromGraph('/deviceManagement/deviceConfigurations');
|
|
console.log(`✓ Fetched ${configs.length} device configuration(s)\n`);
|
|
|
|
// Test 3: Fetch compliance policies
|
|
console.log('Test 3: Fetching compliance policies...');
|
|
const compliance = await fetchFromGraph('/deviceManagement/deviceCompliancePolicies');
|
|
console.log(`✓ Fetched ${compliance.length} compliance policy/policies\n`);
|
|
|
|
console.log('=== All tests passed ✓ ===');
|
|
console.log(`\nTotal policies found: ${configs.length + compliance.length}`);
|
|
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('\n❌ Test failed:', error instanceof Error ? error.message : String(error));
|
|
if (error instanceof Error && error.stack) {
|
|
console.error('\nStack trace:');
|
|
console.error(error.stack);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|