WellNuo/tests/api-discovery.spec.js
Sergei 4a5331b2e4 [TEST] Initial setup - NOT PRODUCTION CODE
⚠️ This is test/experimental code for API integration testing.
Do not use in production.

Includes:
- WellNuo API integration (dashboard, patient context)
- Playwright tests for API verification
- WebView component for dashboard embedding
- API documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-11 13:25:14 -08:00

186 lines
5.3 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const API_BASE = 'https://eluxnetworks.net/function/well-api/api';
const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFuYW5kayIsImV4cCI6MTc2NTQ5MzI5N30.Jon7IJtBscErkt4-8qjas45Irwg_MQTRyS1ASrPGb1U';
const USER_NAME = 'anandk';
const PATIENT_ID = 25; // Ferdinand Zmrzli
test.describe('API Discovery - Find all available functions', () => {
// Common API functions to try
const functionsToTry = [
// Patient related
'patient_details',
'patient_info',
'get_patient',
'patient_data',
'patient_history',
'patient_context',
// Health data
'health_data',
'health_metrics',
'vitals',
'wellness',
'wellness_data',
// Activity
'activity',
'activity_log',
'activity_history',
'location_history',
// Chat/Messages
'chat',
'messages',
'send_message',
'get_messages',
'conversation',
'conversations',
// Alerts
'alerts',
'notifications',
'alert_history',
// Settings
'settings',
'user_settings',
'preferences',
// Reports
'report',
'daily_report',
'weekly_report',
// Other
'status',
'system_status',
'api_list',
'functions',
'help'
];
test('discover available API functions', async ({ request }) => {
console.log('\\n=== TESTING API FUNCTIONS ===\\n');
const workingFunctions = [];
for (const func of functionsToTry) {
const params = new URLSearchParams({
function: func,
user_name: USER_NAME,
token: TOKEN,
patient_id: PATIENT_ID.toString(),
user_id: PATIENT_ID.toString(),
date: '2025-12-10',
nonce: `test-${Date.now()}`
});
try {
const response = await request.post(API_BASE, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: params.toString()
});
const status = response.status();
const text = await response.text();
// Check if function returned valid data
if (status === 200 && text && !text.includes('error') && !text.includes('Error')) {
console.log(`[OK] ${func}: ${text.substring(0, 200)}`);
workingFunctions.push({ function: func, response: text.substring(0, 500) });
} else if (status === 200) {
console.log(`[??] ${func}: ${text.substring(0, 100)}`);
} else {
console.log(`[${status}] ${func}`);
}
} catch (e) {
console.log(`[ERR] ${func}: ${e.message}`);
}
}
console.log('\\n=== WORKING FUNCTIONS ===');
console.log(JSON.stringify(workingFunctions, null, 2));
});
test('explore web interface for more endpoints', async ({ page }) => {
const apiCalls = [];
// Intercept all API calls
page.on('request', req => {
if (req.url().includes('eluxnetworks.net')) {
apiCalls.push({
url: req.url(),
method: req.method(),
postData: req.postData()
});
}
});
// Login and navigate
await page.goto('https://react.eluxnetworks.net/dashboard');
await page.waitForLoadState('networkidle');
// Fill login
await page.locator('input').first().fill('anandk');
await page.locator('input[type="password"]').fill('anandk_8');
await page.locator('button:has-text("Log In")').click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(2000);
// Click on first patient card to see details
const patientCard = page.locator('.bg-white').first();
if (await patientCard.isVisible()) {
await patientCard.click();
await page.waitForTimeout(2000);
await page.screenshot({ path: 'tests/screenshots/patient-details.png', fullPage: true });
}
// Try to find and click on different sections
const sections = ['Health', 'Activity', 'Sleep', 'Alerts', 'Settings', 'Chat', 'Messages'];
for (const section of sections) {
const link = page.locator(`text=${section}`).first();
if (await link.isVisible().catch(() => false)) {
console.log(`Found section: ${section}`);
await link.click().catch(() => {});
await page.waitForTimeout(1000);
}
}
console.log('\\n=== ALL API CALLS CAPTURED ===');
apiCalls.forEach((call, i) => {
console.log(`\\n[${i + 1}] ${call.method} ${call.url}`);
if (call.postData) {
console.log(' Data:', call.postData);
}
});
});
test('test patient context API for chat', async ({ request }) => {
// Test the webhook URL from .env
console.log('\\n=== Testing Patient Context API ===\\n');
const contextUrl = 'https://wellnuo.smartlaunchhub.com/api/patient/context';
try {
const response = await request.get(contextUrl);
console.log(`Status: ${response.status()}`);
const body = await response.text();
console.log(`Response: ${body.substring(0, 1000)}`);
} catch (e) {
console.log(`Error: ${e.message}`);
}
// Try with patient ID
try {
const response = await request.get(`${contextUrl}?patient_id=${PATIENT_ID}`);
console.log(`\\nWith patient_id - Status: ${response.status()}`);
const body = await response.text();
console.log(`Response: ${body.substring(0, 1000)}`);
} catch (e) {
console.log(`Error: ${e.message}`);
}
});
});