@dbs-portal/core-api
Version:
HTTP client and API utilities for DBS Portal
55 lines • 1.59 kB
JavaScript
/**
* MSW server configuration for tests
*/
import { http } from 'msw';
/**
* Test origin URL for MSW handlers
* This ensures that all URLs are properly intercepted
*/
export const TEST_ORIGIN = 'http://localhost:3000';
/**
* Helper function to ensure all handlers have proper URLs
* @param path Path component (e.g., '/api/users')
* @returns Full URL with origin (e.g., 'http://localhost:3000/api/users')
*/
export function testUrl(path) {
// If the path already has http/https, return as is
if (path.startsWith('http://') || path.startsWith('https://')) {
return path;
}
// Ensure path starts with a slash
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
// Return the full URL
return `${TEST_ORIGIN}${normalizedPath}`;
}
/**
* Helper to create a GET handler with proper URL
*/
export function testGet(path, resolver) {
return http.get(testUrl(path), resolver);
}
/**
* Helper to create a POST handler with proper URL
*/
export function testPost(path, resolver) {
return http.post(testUrl(path), resolver);
}
/**
* Helper to create a PUT handler with proper URL
*/
export function testPut(path, resolver) {
return http.put(testUrl(path), resolver);
}
/**
* Helper to create a DELETE handler with proper URL
*/
export function testDelete(path, resolver) {
return http.delete(testUrl(path), resolver);
}
/**
* Helper to create a PATCH handler with proper URL
*/
export function testPatch(path, resolver) {
return http.patch(testUrl(path), resolver);
}
//# sourceMappingURL=test-server-config.js.map