From 26037d592edc4bedff95dd9499e67f8550c05bdb Mon Sep 17 00:00:00 2001 From: Rushil Perera Date: Sun, 10 Aug 2025 19:52:54 -0400 Subject: [PATCH] test: mock Cloudflare worker environment Adds a mock for cloudflare workers to enable testing of code that relies on the cloudflare workers environment. --- bunfig.toml | 1 + src/mocks/cloudflare.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/mocks/cloudflare.ts diff --git a/bunfig.toml b/bunfig.toml index a53b5e8..0614006 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -3,4 +3,5 @@ preload = [ "./testSetup.ts", "./src/mocks/consumet.ts", "./src/mocks/getGoogleAuthToken.ts", + "./src/mocks/cloudflare.ts", ] diff --git a/src/mocks/cloudflare.ts b/src/mocks/cloudflare.ts new file mode 100644 index 0000000..ffb9b24 --- /dev/null +++ b/src/mocks/cloudflare.ts @@ -0,0 +1,24 @@ +import { mock } from "bun:test"; + +mock.module("cloudflare:workers", () => ({ + env: { + ADMIN_SDK_JSON: JSON.stringify({ + type: "service_account", + projectId: "test-26g38", + privateKeyId: "privateKeyId", + privateKey: "privateKey", + clientEmail: "test@test.com", + clientID: "clientId", + authURI: "https://accounts.google.com/o/oauth2/auth", + tokenURI: "https://oauth2.googleapis.com/token", + authProviderX509CertUrl: "https://www.googleapis.com/oauth2/v1/certs", + clientX509CertUrl: + "https://www.googleapis.com/robot/v1/metadata/x509/test%40test.com", + universeDomain: "aniplay.com", + }), + ANIWATCH_URL: "https://aniwatch.to", + CONSUMET_URL: "https://api.consumet.org", + ANILIST_URL: "https://graphql.anilist.co", + GOOGLE_AUTH_URL: "https://www.googleapis.com/oauth2/v4/token", + }, +}));