Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 165831b

Browse files
committed
test: Adds tests for failing header case
1 parent 8958ab8 commit 165831b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: src/client.ts

+3
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,14 @@ export class Collection<TSchema = Document> {
626626
errorText = ((await response.clone().json()) as { error: string })
627627
?.error;
628628
} catch {
629+
/* c8 ignore start */
630+
// used to ensure maximum chance of retieving data from the Realm API
629631
try {
630632
errorText = await response.clone().text();
631633
} catch {
632634
errorText = undefined;
633635
}
636+
/* c8 ignore stop */
634637
}
635638

636639
const fallbackMessage = {

Diff for: test/mocks/handlers.ts

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export const handlers = [
142142
return response(ctx.status(400), ctx.json(errors["400"]));
143143
}
144144

145+
// missing ejson header is a hard 400 error
146+
if (!request.headers.get("content-type")?.includes("application/ejson")) {
147+
return response(ctx.status(400), ctx.json(errors["400"]));
148+
}
149+
145150
// incorrect auth results in a 401 from mongo
146151
let auth = false;
147152
if (request.headers.get("authorization") === `Bearer ${validJWT}`) {

0 commit comments

Comments
 (0)