UNPKG

@kenniy/godeye-data-contracts

Version:

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

197 lines (196 loc) 6 kB
/** * Custom Jest Matchers * Domain-specific assertions for cleaner and more expressive tests */ import { IResponse } from '../../types/response.types'; import { ICriteria } from '../../types/repository.types'; import { IKongUserContext } from '../../types/auth.types'; declare global { namespace jest { interface Matchers<R> { toBeSuccessResponse(): R; toBeErrorResponse(statusCode?: number): R; toBePaginatedResponse(): R; toHaveResponseData(expectedData: any): R; toHaveValidPagination(): R; toHaveMetadata(): R; toBeValidCriteria(): R; toHaveRelations(relations: string[]): R; toHaveWhereConditions(conditions: any): R; toHavePagination(page: number, limit: number): R; toHaveSort(sort: { [key: string]: 'ASC' | 'DESC'; }): R; toHaveSearch(term: string): R; toBeValidKongContext(): R; toHaveUserRole(role: string): R; toHaveAllUserRoles(roles: string[]): R; toHaveProfile(profileId: string, kind?: string): R; toBeValidEntity(): R; toHaveRequiredFields(fields: string[]): R; toHaveRelationData(relationName: string): R; toBeActiveEntity(): R; toBeDeletedEntity(): R; toHaveLength(length: number): R; toBeNonEmptyArray(): R; toContainEntityWithId(id: string): R; toAllHaveProperty(property: string): R; toAllMatchPredicate(predicate: (item: any) => boolean): R; toHaveBeenCalledWithCriteria(criteria: Partial<ICriteria<any>>): R; toHaveBeenCalledWithPopulate(relations: string[]): R; toHaveBeenCalledWithAggregation(): R; } } } /** * Response Matchers */ export declare const responseMatchers: { toBeSuccessResponse(received: IResponse<any>): { message: () => string; pass: boolean; }; toBeErrorResponse(received: IResponse<any>, statusCode?: number): { message: () => string; pass: boolean; }; toBePaginatedResponse(received: IResponse<any>): { message: () => string; pass: any; }; toHaveResponseData(received: IResponse<any>, expectedData: any): { message: () => string; pass: boolean; }; toHaveValidPagination(received: any): { message: () => string; pass: any; }; toHaveMetadata(received: IResponse<any>): { message: () => string; pass: boolean; }; }; /** * Repository/Query Matchers */ export declare const queryMatchers: { toBeValidCriteria(received: ICriteria<any>): { message: () => string; pass: boolean; }; toHaveRelations(received: ICriteria<any>, relations: string[]): { message: () => string; pass: boolean | undefined; }; toHaveWhereConditions(received: ICriteria<any>, conditions: any): { message: () => string; pass: boolean | undefined; }; toHavePagination(received: ICriteria<any>, page: number, limit: number): { message: () => string; pass: boolean; }; toHaveSort(received: ICriteria<any>, sort: { [key: string]: "ASC" | "DESC"; }): { message: () => string; pass: boolean | undefined; }; toHaveSearch(received: ICriteria<any>, term: string): { message: () => string; pass: boolean | undefined; }; }; /** * Kong Auth Matchers */ export declare const authMatchers: { toBeValidKongContext(received: IKongUserContext): { message: () => string; pass: boolean; }; toHaveUserRole(received: IKongUserContext, role: string): { message: () => string; pass: boolean; }; toHaveAllUserRoles(received: IKongUserContext, roles: string[]): { message: () => string; pass: boolean; }; toHaveProfile(received: IKongUserContext, profileId: string, kind?: string): { message: () => string; pass: boolean; }; }; /** * Entity Matchers */ export declare const entityMatchers: { toBeValidEntity(received: any): { message: () => string; pass: any; }; toHaveRequiredFields(received: any, fields: string[]): { message: () => string; pass: any; }; toHaveRelationData(received: any, relationName: string): { message: () => string; pass: any; }; toBeActiveEntity(received: any): { message: () => string; pass: any; }; toBeDeletedEntity(received: any): { message: () => string; pass: any; }; }; /** * Array/Collection Matchers */ export declare const collectionMatchers: { toBeNonEmptyArray(received: any): { message: () => string; pass: boolean; }; toContainEntityWithId(received: any[], id: string): { message: () => string; pass: boolean; }; toAllHaveProperty(received: any[], property: string): { message: () => string; pass: boolean; }; toAllMatchPredicate(received: any[], predicate: (item: any) => boolean): { message: () => string; pass: boolean; }; }; /** * Mock Matchers */ export declare const mockMatchers: { toHaveBeenCalledWithCriteria(received: jest.MockedFunction<any>, criteria: Partial<ICriteria<any>>): { message: () => string; pass: any; }; toHaveBeenCalledWithPopulate(received: jest.MockedFunction<any>, relations: string[]): { message: () => string; pass: any; }; toHaveBeenCalledWithAggregation(received: jest.MockedFunction<any>): { message: () => string; pass: any; }; }; /** * Register all custom matchers */ export declare function registerCustomMatchers(): void; /** * Utility function to register matchers conditionally */ export declare function setupCustomMatchers(): void;