-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
121 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import "./setup" | ||
|
||
import { describe, expect, it, beforeAll, afterAll } from "bun:test" | ||
import { app } from "../index" // Adjust this import based on your app structure | ||
|
||
describe("API Endpoints", () => { | ||
const testServer = app // Your Elysia app instance | ||
|
||
// Example test | ||
it( | ||
"should return 200 for health check", | ||
async () => { | ||
const response = await testServer.handle(new Request("http://localhost/")) | ||
expect(response.status).toBe(200) | ||
expect(await response.text()).toContain("running") | ||
}, | ||
{ timeout: 10000 }, | ||
) | ||
|
||
// Add more endpoint tests here | ||
// Example: | ||
// it("should create a new user", async () => { | ||
// const response = await testServer.handle( | ||
// new Request("http://localhost/api/users", { | ||
// method: "POST", | ||
// headers: { | ||
// "Content-Type": "application/json", | ||
// }, | ||
// body: JSON.stringify({ | ||
// name: "Test User", | ||
// email: "test@example.com", | ||
// }), | ||
// }) | ||
// ); | ||
// expect(response.status).toBe(201); | ||
// }); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { mock } from "bun:test" | ||
|
||
// Mock external services for testing | ||
process.env.NODE_ENV = "test" | ||
|
||
if (!process.env.RESEND_API_KEY) { | ||
process.env.RESEND_API_KEY = "test-key" | ||
} | ||
|
||
if (!process.env.ENCRYPTION_KEY) { | ||
process.env.ENCRYPTION_KEY = "test-key" | ||
} | ||
// If some services are not needed during testing, you can use dummy values | ||
if (!process.env.AMAZON_ACCESS_KEY) { | ||
process.env.AMAZON_ACCESS_KEY = "test-key" | ||
} | ||
if (!process.env.AMAZON_SECRET_ACCESS_KEY) { | ||
process.env.AMAZON_SECRET_ACCESS_KEY = "test-secret" | ||
} | ||
// ... add other environment variables as needed | ||
|
||
// You might want to mock external services | ||
mock.module("../libs/resend", () => ({ | ||
sendEmail: mock().mockResolvedValue(true), | ||
})) | ||
|
||
// doesn't work | ||
// mock.module("../libs/apn.ts", () => ({ | ||
// apnProvider: mock().mockReturnValue(undefined), | ||
// })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import APN from "apn" | ||
|
||
// Configure APN provider | ||
export const apnProvider = new APN.Provider({ | ||
token: { | ||
key: Buffer.from(process.env["APN_KEY"] ?? "", "base64").toString("utf-8"), | ||
keyId: process.env["APN_KEY_ID"] as string, | ||
teamId: process.env["APN_TEAM_ID"] as string, | ||
}, | ||
production: process.env["NODE_ENV"] === "production", | ||
}) | ||
let apnProvider: APN.Provider | undefined | ||
|
||
export const getApnProvider = () => { | ||
if (process.env["NODE_ENV"] === "test") { | ||
return undefined | ||
} | ||
|
||
if (!apnProvider) { | ||
apnProvider = new APN.Provider({ | ||
token: { | ||
key: Buffer.from(process.env["APN_KEY"] ?? "", "base64").toString("utf-8"), | ||
keyId: process.env["APN_KEY_ID"] as string, | ||
teamId: process.env["APN_TEAM_ID"] as string, | ||
}, | ||
production: process.env["NODE_ENV"] === "production", | ||
}) | ||
} | ||
return apnProvider | ||
} | ||
|
||
// Shutdown provider TODO: call on server close | ||
// apnProvider.shutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters