623 lines
21 KiB
JavaScript
623 lines
21 KiB
JavaScript
/**
|
|
* @fileoverview Tests for partner, affiliate, and network business operations MCP tools
|
|
* Tests business data access, partner management, affiliate operations, and network functionality
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach, afterEach } from '@jest/globals';
|
|
import { mockFactory } from '../mocks/mockFactory.js';
|
|
|
|
describe('Partner, Affiliate, and Network Business Operations Tools', () => {
|
|
let mockEnv;
|
|
let toolGenerator;
|
|
|
|
beforeEach(() => {
|
|
mockEnv = mockFactory.createMockEnvironment({
|
|
authTypes: ['partner', 'affiliate', 'network'],
|
|
enableHttpMocks: true,
|
|
enableAuthMocks: true,
|
|
enableHealthcareMocks: true
|
|
});
|
|
|
|
toolGenerator = mockEnv.toolGenerator;
|
|
|
|
// Setup authentication for all business types
|
|
mockFactory.authMocks.setMockCredentials('partner', {
|
|
username: 'test_partner',
|
|
password: 'test_password'
|
|
});
|
|
mockFactory.authMocks.setMockCredentials('affiliate', {
|
|
username: 'test_affiliate',
|
|
password: 'test_password'
|
|
});
|
|
mockFactory.authMocks.setMockCredentials('network', {
|
|
username: 'test_network',
|
|
password: 'test_password'
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
mockFactory.resetAllMocks();
|
|
});
|
|
|
|
describe('Partner Tools', () => {
|
|
describe('partner_get_businessData', () => {
|
|
test('should successfully retrieve partner business data', async () => {
|
|
// Setup
|
|
const toolName = 'partner_get_businessData';
|
|
const parameters = {
|
|
partner_id: 'partner_123',
|
|
data_type: 'analytics'
|
|
};
|
|
|
|
// Mock business data response
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/partner/business-data/partner_123', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
business_data: {
|
|
partner_id: 'partner_123',
|
|
company_name: 'Test Healthcare Partners',
|
|
analytics: {
|
|
monthly_revenue: 50000,
|
|
patient_referrals: 125,
|
|
active_providers: 8,
|
|
satisfaction_score: 4.7
|
|
},
|
|
performance_metrics: {
|
|
conversion_rate: 0.85,
|
|
retention_rate: 0.92,
|
|
growth_rate: 0.15
|
|
},
|
|
last_updated: new Date().toISOString()
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.business_data.partner_id).toBe('partner_123');
|
|
expect(result.data.business_data.analytics.monthly_revenue).toBe(50000);
|
|
expect(result.data.business_data.performance_metrics.conversion_rate).toBe(0.85);
|
|
});
|
|
|
|
test('should handle unauthorized partner data access', async () => {
|
|
const toolName = 'partner_get_businessData';
|
|
const parameters = {
|
|
partner_id: 'unauthorized_partner'
|
|
};
|
|
|
|
// Mock unauthorized access
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/partner/business-data/unauthorized_partner', null, true, {
|
|
response: {
|
|
status: 403,
|
|
data: { error: 'Unauthorized access to partner business data' }
|
|
}
|
|
});
|
|
|
|
await expect(toolGenerator.executeTool(toolName, parameters))
|
|
.rejects.toThrow();
|
|
});
|
|
});
|
|
|
|
describe('partner_post_updateBusinessProfile', () => {
|
|
test('should successfully update partner business profile', async () => {
|
|
// Setup
|
|
const toolName = 'partner_post_updateBusinessProfile';
|
|
const parameters = {
|
|
partner_id: 'partner_123',
|
|
company_name: 'Updated Healthcare Partners',
|
|
business_type: 'Healthcare Services',
|
|
contact_email: 'contact@updated-partners.com',
|
|
phone: '555-0199',
|
|
address: {
|
|
street: '789 Business Ave',
|
|
city: 'Business City',
|
|
state: 'BC',
|
|
zipcode: '98765'
|
|
},
|
|
services: ['Telemedicine', 'Specialist Referrals', 'Lab Services'],
|
|
certifications: ['HIPAA Compliant', 'SOC 2 Type II']
|
|
};
|
|
|
|
// Mock successful profile update
|
|
mockFactory.httpMocks.mockRequest('POST', '/api/partner/update-profile', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
partner: {
|
|
id: 'partner_123',
|
|
company_name: 'Updated Healthcare Partners',
|
|
business_type: 'Healthcare Services',
|
|
contact_email: 'contact@updated-partners.com',
|
|
services: ['Telemedicine', 'Specialist Referrals', 'Lab Services'],
|
|
updated_at: new Date().toISOString()
|
|
},
|
|
message: 'Partner profile updated successfully'
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.partner.company_name).toBe('Updated Healthcare Partners');
|
|
expect(result.data.partner.services).toContain('Telemedicine');
|
|
});
|
|
});
|
|
|
|
describe('partner_get_referralAnalytics', () => {
|
|
test('should successfully retrieve referral analytics', async () => {
|
|
// Setup
|
|
const toolName = 'partner_get_referralAnalytics';
|
|
const parameters = {
|
|
partner_id: 'partner_123',
|
|
date_range: {
|
|
start: '2025-06-01',
|
|
end: '2025-06-30'
|
|
}
|
|
};
|
|
|
|
// Mock referral analytics
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/partner/referral-analytics/partner_123', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
analytics: {
|
|
total_referrals: 45,
|
|
successful_conversions: 38,
|
|
conversion_rate: 0.844,
|
|
revenue_generated: 15000,
|
|
top_referring_sources: [
|
|
{ source: 'Website', count: 20 },
|
|
{ source: 'Direct', count: 15 },
|
|
{ source: 'Social Media', count: 10 }
|
|
],
|
|
monthly_trend: [
|
|
{ month: '2025-04', referrals: 35 },
|
|
{ month: '2025-05', referrals: 42 },
|
|
{ month: '2025-06', referrals: 45 }
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.analytics.total_referrals).toBe(45);
|
|
expect(result.data.analytics.conversion_rate).toBe(0.844);
|
|
expect(result.data.analytics.top_referring_sources).toHaveLength(3);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Affiliate Tools', () => {
|
|
describe('affiliate_get_commissionData', () => {
|
|
test('should successfully retrieve affiliate commission data', async () => {
|
|
// Setup
|
|
const toolName = 'affiliate_get_commissionData';
|
|
const parameters = {
|
|
affiliate_id: 'affiliate_456',
|
|
period: 'monthly'
|
|
};
|
|
|
|
// Mock commission data response
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/affiliate/commission-data/affiliate_456', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
commission_data: {
|
|
affiliate_id: 'affiliate_456',
|
|
current_period: {
|
|
period: 'June 2025',
|
|
total_commission: 2500.00,
|
|
referrals_count: 15,
|
|
conversion_rate: 0.75,
|
|
pending_commission: 500.00,
|
|
paid_commission: 2000.00
|
|
},
|
|
commission_structure: {
|
|
base_rate: 0.10,
|
|
tier_bonuses: {
|
|
tier_1: { min_referrals: 10, bonus_rate: 0.02 },
|
|
tier_2: { min_referrals: 25, bonus_rate: 0.05 }
|
|
}
|
|
},
|
|
payment_history: [
|
|
{
|
|
date: '2025-05-31',
|
|
amount: 2200.00,
|
|
status: 'paid'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.commission_data.current_period.total_commission).toBe(2500.00);
|
|
expect(result.data.commission_data.current_period.referrals_count).toBe(15);
|
|
expect(result.data.commission_data.commission_structure.base_rate).toBe(0.10);
|
|
});
|
|
});
|
|
|
|
describe('affiliate_post_submitReferral', () => {
|
|
test('should successfully submit new referral', async () => {
|
|
// Setup
|
|
const toolName = 'affiliate_post_submitReferral';
|
|
const parameters = {
|
|
affiliate_id: 'affiliate_456',
|
|
referral_data: {
|
|
customer_name: 'John Doe',
|
|
customer_email: 'john.doe@test.com',
|
|
customer_phone: '555-0123',
|
|
service_interest: 'Telemedicine',
|
|
referral_source: 'Website',
|
|
notes: 'Interested in virtual consultations'
|
|
}
|
|
};
|
|
|
|
// Mock successful referral submission
|
|
mockFactory.httpMocks.mockRequest('POST', '/api/affiliate/submit-referral', {
|
|
status: 201,
|
|
data: {
|
|
success: true,
|
|
referral: {
|
|
id: 'referral_789',
|
|
affiliate_id: 'affiliate_456',
|
|
customer_name: 'John Doe',
|
|
customer_email: 'john.doe@test.com',
|
|
service_interest: 'Telemedicine',
|
|
status: 'pending',
|
|
tracking_code: 'REF789ABC',
|
|
submitted_at: new Date().toISOString()
|
|
},
|
|
message: 'Referral submitted successfully'
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.referral.customer_name).toBe('John Doe');
|
|
expect(result.data.referral.status).toBe('pending');
|
|
expect(result.data.referral.tracking_code).toBe('REF789ABC');
|
|
});
|
|
|
|
test('should validate referral data completeness', async () => {
|
|
const toolName = 'affiliate_post_submitReferral';
|
|
|
|
// Test missing required fields
|
|
const incompleteParams = {
|
|
affiliate_id: 'affiliate_456',
|
|
referral_data: {
|
|
customer_name: 'John Doe'
|
|
// Missing email and other required fields
|
|
}
|
|
};
|
|
|
|
await expect(toolGenerator.executeTool(toolName, incompleteParams))
|
|
.rejects.toThrow();
|
|
});
|
|
});
|
|
|
|
describe('affiliate_get_performanceMetrics', () => {
|
|
test('should successfully retrieve affiliate performance metrics', async () => {
|
|
// Setup
|
|
const toolName = 'affiliate_get_performanceMetrics';
|
|
const parameters = {
|
|
affiliate_id: 'affiliate_456',
|
|
timeframe: 'last_6_months'
|
|
};
|
|
|
|
// Mock performance metrics
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/affiliate/performance-metrics/affiliate_456', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
metrics: {
|
|
total_referrals: 85,
|
|
successful_conversions: 68,
|
|
conversion_rate: 0.80,
|
|
total_commission_earned: 12500.00,
|
|
average_commission_per_referral: 147.06,
|
|
ranking: {
|
|
current_rank: 15,
|
|
total_affiliates: 200,
|
|
percentile: 92.5
|
|
},
|
|
monthly_breakdown: [
|
|
{ month: '2025-01', referrals: 12, conversions: 10 },
|
|
{ month: '2025-02', referrals: 15, conversions: 12 },
|
|
{ month: '2025-03', referrals: 18, conversions: 14 }
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.metrics.total_referrals).toBe(85);
|
|
expect(result.data.metrics.conversion_rate).toBe(0.80);
|
|
expect(result.data.metrics.ranking.current_rank).toBe(15);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Network Tools', () => {
|
|
describe('network_get_networkStatus', () => {
|
|
test('should successfully retrieve network status', async () => {
|
|
// Setup
|
|
const toolName = 'network_get_networkStatus';
|
|
const parameters = {
|
|
network_id: 'network_789'
|
|
};
|
|
|
|
// Mock network status response
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/network/status/network_789', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
network_status: {
|
|
network_id: 'network_789',
|
|
network_name: 'Healthcare Network East',
|
|
status: 'active',
|
|
member_count: 45,
|
|
active_connections: 42,
|
|
health_score: 0.95,
|
|
uptime_percentage: 99.8,
|
|
last_health_check: new Date().toISOString(),
|
|
regional_coverage: [
|
|
{ region: 'Northeast', providers: 15 },
|
|
{ region: 'Southeast', providers: 18 },
|
|
{ region: 'Midwest', providers: 12 }
|
|
],
|
|
service_availability: {
|
|
telemedicine: true,
|
|
emergency_services: true,
|
|
specialist_referrals: true,
|
|
lab_services: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.network_status.network_name).toBe('Healthcare Network East');
|
|
expect(result.data.network_status.member_count).toBe(45);
|
|
expect(result.data.network_status.health_score).toBe(0.95);
|
|
expect(result.data.network_status.service_availability.telemedicine).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('network_post_updateNetworkConfig', () => {
|
|
test('should successfully update network configuration', async () => {
|
|
// Setup
|
|
const toolName = 'network_post_updateNetworkConfig';
|
|
const parameters = {
|
|
network_id: 'network_789',
|
|
configuration: {
|
|
max_concurrent_connections: 100,
|
|
load_balancing_enabled: true,
|
|
failover_enabled: true,
|
|
security_level: 'high',
|
|
data_encryption: 'AES-256',
|
|
backup_frequency: 'daily',
|
|
monitoring_interval: 300,
|
|
alert_thresholds: {
|
|
cpu_usage: 80,
|
|
memory_usage: 85,
|
|
disk_usage: 90
|
|
}
|
|
}
|
|
};
|
|
|
|
// Mock successful configuration update
|
|
mockFactory.httpMocks.mockRequest('POST', '/api/network/update-config', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
network_config: {
|
|
network_id: 'network_789',
|
|
max_concurrent_connections: 100,
|
|
load_balancing_enabled: true,
|
|
security_level: 'high',
|
|
updated_at: new Date().toISOString(),
|
|
config_version: '2.1.0'
|
|
},
|
|
message: 'Network configuration updated successfully'
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.network_config.max_concurrent_connections).toBe(100);
|
|
expect(result.data.network_config.security_level).toBe('high');
|
|
expect(result.data.network_config.config_version).toBe('2.1.0');
|
|
});
|
|
});
|
|
|
|
describe('network_get_memberDirectory', () => {
|
|
test('should successfully retrieve network member directory', async () => {
|
|
// Setup
|
|
const toolName = 'network_get_memberDirectory';
|
|
const parameters = {
|
|
network_id: 'network_789',
|
|
filters: {
|
|
region: 'Northeast',
|
|
specialty: 'Cardiology'
|
|
}
|
|
};
|
|
|
|
// Mock member directory response
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/network/member-directory/network_789', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
members: [
|
|
{
|
|
id: 'member_001',
|
|
name: 'Dr. Sarah Johnson',
|
|
specialty: 'Cardiology',
|
|
region: 'Northeast',
|
|
status: 'active',
|
|
contact: {
|
|
email: 'sarah.johnson@cardio.com',
|
|
phone: '555-0201'
|
|
},
|
|
services: ['Consultation', 'Diagnostic', 'Surgery'],
|
|
rating: 4.8,
|
|
availability: 'high'
|
|
},
|
|
{
|
|
id: 'member_002',
|
|
name: 'Dr. Michael Chen',
|
|
specialty: 'Cardiology',
|
|
region: 'Northeast',
|
|
status: 'active',
|
|
contact: {
|
|
email: 'michael.chen@heart.com',
|
|
phone: '555-0202'
|
|
},
|
|
services: ['Consultation', 'Diagnostic'],
|
|
rating: 4.9,
|
|
availability: 'medium'
|
|
}
|
|
],
|
|
total_count: 2,
|
|
filters_applied: {
|
|
region: 'Northeast',
|
|
specialty: 'Cardiology'
|
|
}
|
|
}
|
|
});
|
|
|
|
// Execute
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
// Assert
|
|
expect(result.success).toBe(true);
|
|
expect(result.data.members).toHaveLength(2);
|
|
expect(result.data.members[0].specialty).toBe('Cardiology');
|
|
expect(result.data.filters_applied.region).toBe('Northeast');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Business Operations Security Tests', () => {
|
|
test('should require appropriate authentication for business operations', async () => {
|
|
// Clear authentication
|
|
mockFactory.authMocks.reset();
|
|
|
|
const toolName = 'partner_get_businessData';
|
|
const parameters = {
|
|
partner_id: 'partner_123'
|
|
};
|
|
|
|
// Mock authentication failure
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/partner/business-data/partner_123', null, true, {
|
|
response: {
|
|
status: 401,
|
|
data: { error: 'Business authentication required' }
|
|
}
|
|
});
|
|
|
|
await expect(toolGenerator.executeTool(toolName, parameters))
|
|
.rejects.toThrow();
|
|
});
|
|
|
|
test('should validate business data access permissions', async () => {
|
|
const toolName = 'affiliate_get_commissionData';
|
|
const parameters = {
|
|
affiliate_id: 'restricted_affiliate'
|
|
};
|
|
|
|
// Mock insufficient permissions
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/affiliate/commission-data/restricted_affiliate', null, true, {
|
|
response: {
|
|
status: 403,
|
|
data: { error: 'Insufficient permissions for commission data access' }
|
|
}
|
|
});
|
|
|
|
await expect(toolGenerator.executeTool(toolName, parameters))
|
|
.rejects.toThrow();
|
|
});
|
|
|
|
test('should audit business operations for compliance', async () => {
|
|
const toolName = 'network_post_updateNetworkConfig';
|
|
const parameters = {
|
|
network_id: 'network_789',
|
|
configuration: {
|
|
security_level: 'high'
|
|
}
|
|
};
|
|
|
|
// Mock response with audit trail
|
|
mockFactory.httpMocks.mockRequest('POST', '/api/network/update-config', {
|
|
status: 200,
|
|
data: {
|
|
success: true,
|
|
network_config: {
|
|
network_id: 'network_789',
|
|
security_level: 'high'
|
|
},
|
|
auditTrail: {
|
|
updatedBy: 'network_admin_123',
|
|
updatedAt: new Date().toISOString(),
|
|
action: 'network_config_update',
|
|
changes: ['security_level'],
|
|
ipAddress: '127.0.0.1'
|
|
}
|
|
}
|
|
});
|
|
|
|
const result = await toolGenerator.executeTool(toolName, parameters);
|
|
|
|
expect(result.data.auditTrail).toBeDefined();
|
|
expect(result.data.auditTrail.action).toBe('network_config_update');
|
|
expect(result.data.auditTrail.changes).toContain('security_level');
|
|
});
|
|
|
|
test('should handle business data rate limiting', async () => {
|
|
const toolName = 'partner_get_referralAnalytics';
|
|
const parameters = {
|
|
partner_id: 'partner_123'
|
|
};
|
|
|
|
// Mock rate limiting
|
|
mockFactory.httpMocks.mockRequest('GET', '/api/partner/referral-analytics/partner_123', null, true, {
|
|
response: {
|
|
status: 429,
|
|
data: { error: 'Rate limit exceeded for business data requests' }
|
|
}
|
|
});
|
|
|
|
await expect(toolGenerator.executeTool(toolName, parameters))
|
|
.rejects.toThrow();
|
|
});
|
|
});
|
|
});
|