initForTests<TProfile> static method

  1. @visibleForTesting
Future<CkAuthService<TProfile>> initForTests<TProfile>({
  1. required CkAuthConfig<TProfile> config,
  2. required CkAuthTokenManager tokenManager,
})

Test-only factory: creates a fully wired service without calling restoreSession or touching any platform channels. Resets the singleton.

Implementation

@visibleForTesting
static Future<CkAuthService<TProfile>> initForTests<TProfile>({
  required CkAuthConfig<TProfile> config,
  required CkAuthTokenManager tokenManager,
}) async {
  final authState = CkAuthStateController();
  final profileExtractor = CkProfileExtractor<TProfile>(
    extractors: config.extractors,
  );
  final otpManager = CkOtpFlowManager(
    config: config.otpConfig,
    extractors: config.extractors,
    sendUrl: config.endpoints.sendOtp,
    verifyUrl: config.endpoints.verifyOtp,
    verifyForgetUrl: config.endpoints.verifyForgetOtp,
    sendMethod: config.endpoints.sendOtpMethod,
    verifyMethod: config.endpoints.verifyOtpMethod,
    verifyForgotMethod: config.endpoints.verifyForgotOtpMethod,
  );
  final logoutHandler = CkLogoutHandler(
    tokenManager: tokenManager,
    profileExtractor: profileExtractor,
    otpManager: otpManager,
    stateController: authState,
    handlers: config.handlers,
    logoutUrl: config.endpoints.logout,
    logoutMethod: config.endpoints.logoutMethod,
  );
  final socialManager = CkSocialAuthManager<TProfile>(
    config: config.socialLoginConfig,
    tokenManager: tokenManager,
    profileExtractor: profileExtractor,
    stateController: authState,
    logoutHandler: logoutHandler,
    defaultExtractors: config.extractors,
  );
  final loadingController = CkAuthLoadingController();
  final service = CkAuthService<TProfile>._(
    tokenManager: tokenManager,
    authState: authState,
    profileExtractor: profileExtractor,
    otpManager: otpManager,
    logoutHandler: logoutHandler,
    socialManager: socialManager,
    config: config,
    loadingController: loadingController,
  );
  _instance = service;
  return service;
}