import 'package:flutter_test/flutter_test.dart';

import 'package:superport_v2/core/permissions/permission_manager.dart';
import 'package:superport_v2/features/auth/domain/entities/auth_permission.dart';

void main() {
  group('AuthPermission.toPermissionMap', () {
    test('백엔드 표준 문자열을 프런트 권한으로 매핑한다', () {
      final permission = AuthPermission(
        resource: '/approvals',
        actions: ['read', 'update', 'approve'],
      );

      final result = permission.toPermissionMap();

      expect(result, contains('/approvals'));
      final actions = result['/approvals']!;
      expect(actions.contains(PermissionAction.view), isTrue);
      expect(actions.contains(PermissionAction.edit), isTrue);
      expect(actions.contains(PermissionAction.approve), isTrue);
    });

    test('알 수 없는 문자열은 무시해 빈 권한으로 반환한다', () {
      final permission = AuthPermission(
        resource: '/dashboard',
        actions: ['unknown', 'legacy'],
      );

      final result = permission.toPermissionMap();

      expect(result, isEmpty);
    });
  });
}
