runTestSuite static method

Future<Map<String, bool>> runTestSuite(
  1. ULinkConfig config
)

Creates a comprehensive test suite for ULink functionality.

This method runs a series of tests to validate ULink integration.

config - The ULink config to test with Returns a map of test results

Implementation

static Future<Map<String, bool>> runTestSuite(ULinkConfig config) async {
  final results = <String, bool>{};

  ULinkTestingUtilities._log('Running ULink test suite');

  // Test 1: Config validation
  results['config_validation'] = ULinkTestingUtilities.validateConfig(config);

  // Test 2: SDK initialization
  try {
    await ULink.instance.initialize(config);
    results['sdk_initialization'] = true;
    ULinkTestingUtilities._log('SDK initialization test passed');
  } catch (e) {
    results['sdk_initialization'] = false;
    ULinkTestingUtilities._log('SDK initialization test failed: $e');
  }

  // Test 3: Link creation
  try {
    final parameters = ULinkTestingUtilities.createMockParameters();
    final response = await ULink.instance.createLink(
      parameters,
    );
    results['link_creation'] =
        response.success && response.url != null && response.url!.isNotEmpty;
    ULinkTestingUtilities._log(
      'Link creation test: ${results['link_creation'] ?? false ? 'passed' : 'failed'}',
    );
  } catch (e) {
    results['link_creation'] = false;
    ULinkTestingUtilities._log('Link creation test failed: $e');
  }

  // Test 4: Session management
  try {
    final sessionId = await ULinkTestingUtilities.createTestSession();
    results['session_creation'] = sessionId != null;

    if (sessionId != null) {
      final hasActiveSession = await ULink.instance
          .hasActiveSession();
      results['session_active_check'] = hasActiveSession;

      await ULink.instance.endSession();
      results['session_end'] = true;
    } else {
      results['session_active_check'] = false;
      results['session_end'] = false;
    }

    ULinkTestingUtilities._log('Session management tests completed');
  } catch (e) {
    results['session_creation'] = false;
    results['session_active_check'] = false;
    results['session_end'] = false;
    ULinkTestingUtilities._log('Session management tests failed: $e');
  }

  // Test 5: Installation ID
  try {
    final installationId = await ULink.instance
        .getInstallationId();
    results['installation_id'] = installationId?.isNotEmpty ?? false;
    ULinkTestingUtilities._log(
      'Installation ID test: ${(results['installation_id'] == true) ? 'passed' : 'failed'}',
    );
  } catch (e) {
    results['installation_id'] = false;
    ULinkTestingUtilities._log('Installation ID test failed: $e');
  }

  final passedTests = results.values.where((result) => result).length;
  final totalTests = results.length;

  ULinkTestingUtilities._log(
    'Test suite completed: $passedTests/$totalTests tests passed',
  );

  return results;
}