(
options: { failInstantRecordings?: boolean } = {},
)
| 75 | }; |
| 76 | |
| 77 | const createMockCapServer = async ( |
| 78 | options: { failInstantRecordings?: boolean } = {}, |
| 79 | ) => { |
| 80 | const server = createServer(async (request, response) => { |
| 81 | const url = new URL(request.url ?? "/", "http://127.0.0.1"); |
| 82 | if (request.method === "OPTIONS") { |
| 83 | sendJson(response, 204, {}); |
| 84 | return; |
| 85 | } |
| 86 | if (request.method === "GET" && url.pathname === "/capture.html") { |
| 87 | response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); |
| 88 | response.end( |
| 89 | `<!doctype html><html><head><title>Cap Close UI Target</title></head><body style="background:#321"><h1>Close UI page</h1></body></html>`, |
| 90 | ); |
| 91 | return; |
| 92 | } |
| 93 | if ( |
| 94 | request.method === "GET" && |
| 95 | url.pathname === "/api/extension/bootstrap" |
| 96 | ) { |
| 97 | sendJson(response, 200, { |
| 98 | user: { id: "user-e2e", email: "e2e@cap.test" }, |
| 99 | organization: { id: "org-e2e", name: "E2E" }, |
| 100 | plan: { isPro: true, maxRecordingSeconds: 600 }, |
| 101 | }); |
| 102 | return; |
| 103 | } |
| 104 | if ( |
| 105 | request.method === "POST" && |
| 106 | url.pathname === "/api/extension/instant-recordings" |
| 107 | ) { |
| 108 | await readRequestBody(request); |
| 109 | if (options.failInstantRecordings) { |
| 110 | sendJson(response, 500, { error: "mock instant recording failure" }); |
| 111 | return; |
| 112 | } |
| 113 | sendJson(response, 200, { |
| 114 | id: "video-close-ui", |
| 115 | shareUrl: `${origin}/share/video-close-ui`, |
| 116 | upload: { type: "multipart" }, |
| 117 | }); |
| 118 | return; |
| 119 | } |
| 120 | if ( |
| 121 | request.method === "POST" && |
| 122 | url.pathname === "/api/upload/multipart/initiate" |
| 123 | ) { |
| 124 | await readRequestBody(request); |
| 125 | sendJson(response, 200, { uploadId: "upload-close", provider: "s3" }); |
| 126 | return; |
| 127 | } |
| 128 | if ( |
| 129 | request.method === "POST" && |
| 130 | url.pathname === "/api/upload/multipart/presign-part" |
| 131 | ) { |
| 132 | await readRequestBody(request); |
| 133 | sendJson(response, 200, { |
| 134 | presignedUrl: `${origin}/mock-s3/part`, |
no test coverage detected