(input: {
headers?: OriginHeaders;
status: number;
allowOrigin?: string | null | ((server: TestOrpcServer) => string | null);
allowHttpOrigin?: boolean;
})
| 245 | } |
| 246 | |
| 247 | async function expectHttpOriginCase(input: { |
| 248 | headers?: OriginHeaders; |
| 249 | status: number; |
| 250 | allowOrigin?: string | null | ((server: TestOrpcServer) => string | null); |
| 251 | allowHttpOrigin?: boolean; |
| 252 | }): Promise<void> { |
| 253 | await withTestOrpcServer( |
| 254 | async (server) => { |
| 255 | const response = await fetch(`${server.baseUrl}/api/spec.json`, { |
| 256 | headers: resolveOriginHeaders(input.headers, server), |
| 257 | }); |
| 258 | |
| 259 | expect(response.status).toBe(input.status); |
| 260 | if (input.allowOrigin !== undefined) { |
| 261 | const allowOrigin = |
| 262 | typeof input.allowOrigin === "function" ? input.allowOrigin(server) : input.allowOrigin; |
| 263 | expect(response.headers.get("access-control-allow-origin")).toBe(allowOrigin); |
| 264 | if (allowOrigin != null) { |
| 265 | expect(response.headers.get("access-control-allow-credentials")).toBe("true"); |
| 266 | } |
| 267 | } |
| 268 | }, |
| 269 | input.allowHttpOrigin ? { allowHttpOrigin: true } : {} |
| 270 | ); |
| 271 | } |
| 272 | |
| 273 | async function expectWebSocketOriginCase(input: { |
| 274 | headers?: OriginHeaders; |
no test coverage detected