import 'package:flutter_test/flutter_test.dart';
import 'package:userfront/features/auth/domain/password_login_flow_policy.dart';

void main() {
  group('password_login_flow_policy', () {
    test('redirectTo가 있으면 OIDC redirect를 우선한다', () {
      final action = decidePasswordLoginNextAction(
        hasLoginChallenge: true,
        redirectTo:
            'https://sso-test.hmac.kr/oidc/oauth2/auth?login_verifier=a',
        jwt: 'jwt-token',
      );

      expect(action, PasswordLoginNextAction.redirectToOidc);
    });

    test('OIDC challenge가 있고 redirectTo가 없으면 accept를 시도한다', () {
      final action = decidePasswordLoginNextAction(
        hasLoginChallenge: true,
        redirectTo: null,
        jwt: 'jwt-token',
      );

      expect(action, PasswordLoginNextAction.acceptOidc);
    });

    test('OIDC challenge가 없고 jwt가 있으면 로컬 로그인 완료로 진행한다', () {
      final action = decidePasswordLoginNextAction(
        hasLoginChallenge: false,
        redirectTo: null,
        jwt: 'jwt-token',
      );

      expect(action, PasswordLoginNextAction.localLogin);
    });

    test('redirectTo/jwt 모두 없으면 invalid로 처리한다', () {
      final action = decidePasswordLoginNextAction(
        hasLoginChallenge: false,
        redirectTo: null,
        jwt: null,
      );

      expect(action, PasswordLoginNextAction.invalid);
    });
  });
}
