Skip to content

Commit

Permalink
test: improve GET /activites test case✅
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamvijaywargi committed Nov 23, 2024
1 parent c27f867 commit 1d42adb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ NODE_ENV=development
LOG_LEVEL=debug
PORT=8998
DATABASE_URL=postgresql://root:root@localhost:5432/finance-management-api
ALLOWED_ORIGINS="http://localhost:3000,http://localhost:8998" # if multiple origins separate by comma
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules/

.env
.env.test

#logs
logs
Expand Down
2 changes: 1 addition & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
dbCredentials: {
url: env.DATABASE_URL,
},
verbose: true,
verbose: env.NODE_ENV === "development",
strict: true,
casing: "snake_case",
});
36 changes: 34 additions & 2 deletions src/modules/activities/activity.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { beforeEach, describe, expect, it } from "bun:test";
import { $ } from "bun";
import {
afterAll,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "bun:test";
import { testClient } from "hono/testing";

import { createApp, createTestApp } from "@/common/lib/create-app.lib";
Expand All @@ -16,14 +24,38 @@ const activityClient = testClient(createApp().route("/", activityRouter));
describe("Activities List", () => {
let sessionToken = "";

beforeAll(async () => {
await $`bun drizzle-kit push --force`;

const testAuthRouter = createTestApp(authRouter);

const userResponse = await testAuthRouter.request("/auth/register", {
method: "POST",
body: JSON.stringify({
email: "user1@yopmail.com",
password: "ksjhdfjh&*^&%^5675",
}),
headers: new Headers({ "Content-Type": "application/json" }),
});

const userResult = await userResponse.json();

// @ts-expect-error session is available
sessionToken = userResult.data.session;
});

afterAll(async () => {
await $`bun run db:clear`;
});

beforeEach(async () => {
const testAuthRouter = createTestApp(authRouter);

const userResponse = await testAuthRouter.request("/auth/login", {
method: "POST",
body: JSON.stringify({
email: "user1@yopmail.com",
password: "12345678",
password: "ksjhdfjh&*^&%^5675",
}),
headers: new Headers({ "Content-Type": "application/json" }),
});
Expand Down

0 comments on commit 1d42adb

Please sign in to comment.