@dbs-portal/core-api
Version:
HTTP client and API utilities for DBS Portal
197 lines • 4.94 kB
TypeScript
/**
* MSW testing utilities
*/
import { setupServer } from 'msw/node';
import type { RequestHandler } from 'msw';
import type { QueryClient } from '@tanstack/react-query';
/**
* Test server instance
*/
declare let testServer: ReturnType<typeof setupServer> | null;
/**
* Create test server with handlers
*/
export declare function createTestServer(customHandlers?: RequestHandler[]): ReturnType<typeof setupServer>;
/**
* Setup MSW for testing
*/
export declare function setupMSWTesting(customHandlers?: RequestHandler[]): {
server: import("msw/node").SetupServerApi;
addHandlers: (...handlers: RequestHandler[]) => void | undefined;
resetHandlers: () => void | undefined;
restoreHandlers: () => void | undefined;
cleanup: () => void;
teardown: () => void;
};
/**
* Create test query client with MSW
*/
export declare function createTestQueryClient(customHandlers?: RequestHandler[]): Promise<QueryClient>;
/**
* Wait for all queries to settle
*/
export declare function waitForQueries(queryClient: QueryClient, timeout?: number): Promise<void>;
/**
* Mock API response helpers
*/
export declare const mockHelpers: {
/**
* Create successful API response
*/
success<T>(data: T, message?: string): {
success: boolean;
data: T;
message: string;
meta: {
timestamp: string;
requestId: string;
version: string;
};
};
/**
* Create error API response
*/
error(message: string, code?: string, _status?: number): {
success: boolean;
message: string;
errors: {
code: string;
message: string;
}[];
meta: {
timestamp: string;
requestId: string;
version: string;
};
};
/**
* Create validation error response
*/
validationError(errors: Array<{
field: string;
message: string;
}>): {
success: boolean;
message: string;
errors: {
code: string;
message: string;
field: string;
}[];
meta: {
timestamp: string;
requestId: string;
version: string;
};
};
/**
* Create paginated response
*/
paginated<T>(items: T[], page?: number, pageSize?: number, total?: number): {
success: boolean;
data: {
items: T[];
totalCount: number;
pageSize: number;
currentPage: number;
totalPages: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
};
message: string;
meta: {
timestamp: string;
requestId: string;
version: string;
};
};
};
/**
* Test data factories
*/
export declare const testFactories: {
/**
* Create test user
*/
user(overrides?: Partial<any>): {
id: string;
email: string;
username: string;
firstName: string;
lastName: string;
isActive: boolean;
createdAt: string;
updatedAt: string;
};
/**
* Create test file
*/
file(overrides?: Partial<any>): {
id: string;
filename: string;
originalName: string;
mimeType: string;
size: number;
url: string;
uploadedAt: string;
};
/**
* Create test auth tokens
*/
authTokens(overrides?: Partial<any>): {
accessToken: string;
refreshToken: string;
expiresAt: string;
tokenType: string;
};
};
/**
* Test assertion helpers
*/
export declare const testAssertions: {
/**
* Assert API response structure
*/
isApiResponse(response: any): boolean;
/**
* Assert successful API response
*/
isSuccessResponse(response: any): boolean;
/**
* Assert error API response
*/
isErrorResponse(response: any): boolean;
/**
* Assert paginated response
*/
isPaginatedResponse(response: any): boolean;
};
/**
* Test lifecycle helpers
*/
export declare const testLifecycle: {
/**
* Setup function for beforeAll/beforeEach
*/
setup(customHandlers?: RequestHandler[]): {
server: import("msw/node").SetupServerApi;
addHandlers: (...handlers: RequestHandler[]) => void | undefined;
resetHandlers: () => void | undefined;
restoreHandlers: () => void | undefined;
cleanup: () => void;
teardown: () => void;
};
/**
* Cleanup function for afterEach
*/
cleanup(mswInstance: ReturnType<typeof setupMSWTesting>): void;
/**
* Teardown function for afterAll
*/
teardown(mswInstance: ReturnType<typeof setupMSWTesting>): void;
};
/**
* Export test server for direct access
*/
export { testServer };
//# sourceMappingURL=test-utils.d.ts.map