UNPKG

@kenniy/godeye-data-contracts

Version:

Enterprise-grade base repository architecture for GOD-EYE microservices with zero overhead and maximum code reuse

127 lines (126 loc) 4.48 kB
/** * Kong Authentication Context Factory * Provides consistent Kong user context generation for auth testing */ import { ExecutionContext } from '@nestjs/common'; import { IKongUserContext } from '../../types/auth.types'; export interface MockKongHeaders { [key: string]: string | string[]; } export interface MockRequest { headers: MockKongHeaders; url?: string; route?: { path: string; }; user?: IKongUserContext; } export interface MockHttpContext { getRequest: jest.MockedFunction<() => MockRequest>; getResponse: jest.MockedFunction<() => any>; } /** * Kong Context Factory - Creates Kong authentication contexts and headers */ export declare class KongContextFactory { private static userIdCounter; private static generateUserId; /** * Creates basic Kong headers with required fields */ static createBasicHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; /** * Creates complete Kong headers with all optional fields */ static createCompleteHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; /** * Creates Kong user context object (extracted from headers) */ static createUserContext(overrides?: Partial<IKongUserContext>): IKongUserContext; /** * Creates user context with multiple roles */ static createUserContextWithRoles(roles?: string[], overrides?: Partial<IKongUserContext>): IKongUserContext; /** * Creates mock request object with Kong headers */ static createMockRequest(headers?: MockKongHeaders, overrides?: Partial<MockRequest>): MockRequest; /** * Creates mock execution context for guard testing */ static createMockExecutionContext(request?: Partial<MockRequest>, response?: any): jest.Mocked<ExecutionContext>; /** * Creates headers for specific user types */ static createAdminHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; static createDoctorHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; static createBusinessHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; /** * Creates headers with missing required fields (for error testing) */ static createIncompleteHeaders(missingFields?: string[]): MockKongHeaders; /** * Creates headers with array values (for normalization testing) */ static createArrayHeaders(overrides?: Partial<MockKongHeaders>): MockKongHeaders; /** * Reset user ID counter for consistent test runs */ static resetUserIdCounter(): void; } /** * Kong Context Builder - Fluent interface for complex context creation */ export declare class KongContextBuilder { private headers; private request; static create(): KongContextBuilder; withUserId(userId: string): KongContextBuilder; withEmail(email: string): KongContextBuilder; withRoles(roles: string[]): KongContextBuilder; withProfile(profileId: string, kind: string): KongContextBuilder; withName(firstName: string, lastName: string): KongContextBuilder; withPhone(phone: string): KongContextBuilder; withUrl(url: string): KongContextBuilder; withExistingHeaders(existingHeaders: MockKongHeaders): KongContextBuilder; buildHeaders(): MockKongHeaders; buildRequest(): MockRequest; buildExecutionContext(): jest.Mocked<ExecutionContext>; } /** * Auth Scenario Factory - Common authentication scenarios */ export declare class AuthScenarios { /** * Valid authenticated user scenario */ static authenticatedUser(): jest.Mocked<ExecutionContext>; /** * Admin user scenario */ static adminUser(): jest.Mocked<ExecutionContext>; /** * Doctor user scenario */ static doctorUser(): jest.Mocked<ExecutionContext>; /** * Business user scenario */ static businessUser(): jest.Mocked<ExecutionContext>; /** * Unauthenticated user scenario (no headers) */ static unauthenticatedUser(): jest.Mocked<ExecutionContext>; /** * Invalid user scenario (missing required fields) */ static invalidUser(missingFields?: string[]): jest.Mocked<ExecutionContext>; /** * User accessing health check endpoint (should skip auth) */ static healthCheckAccess(): jest.Mocked<ExecutionContext>; /** * User with insufficient roles */ static userWithInsufficientRoles(): jest.Mocked<ExecutionContext>; }