Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(ci): add api integration scaffolding

Tin9665488a1d55
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3e7561f05..4b50cf0ce 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -50,3 +50,47 @@ jobs:
- name: Run unit tests
run: pnpm test
+
+ integration:
+ runs-on: ubuntu-24.04
+ services:
+ postgres:
+ image: postgres:16
+ env:
+ POSTGRES_DB: kaneo_test
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: postgres
+ ports:
+ - 5432:5432
+ options: >-
+ --health-cmd "pg_isready -U postgres -d kaneo_test"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ env:
+ NODE_ENV: test
+ AUTH_SECRET: test-secret-with-at-least-32-chars
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/kaneo_test
+ KANEO_API_URL: http://localhost:1337
+ KANEO_CLIENT_URL: http://localhost:5173
+ DISABLE_GUEST_ACCESS: "false"
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ version: 10.32.1
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: pnpm
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Run API integration tests
+ run: pnpm test:integration
diff --git a/apps/api/.env.test.example b/apps/api/.env.test.example
new file mode 100644
index 000000000..eb0eb11b4
--- /dev/null
+++ b/apps/api/.env.test.example
@@ -0,0 +1,6 @@
+NODE_ENV=test
+AUTH_SECRET=test-secret-with-at-least-32-chars
+DATABASE_URL=postgresql://postgres:postgres@localhost:5432/kaneo_test
+KANEO_API_URL=http://localhost:1337
+KANEO_CLIENT_URL=http://localhost:5173
+DISABLE_GUEST_ACCESS=false
diff --git a/apps/api/package.json b/apps/api/package.json
index d3fffbd19..21a3a5cf8 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -17,6 +17,8 @@
"build": "esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --packages=external --external:fs --external:path --external:crypto --external:os --external:util --external:stream --external:buffer --external:events --external:url --external:querystring --external:http --external:https --external:net --external:tls --external:zlib",
"lint": "biome check --write .",
"test": "vitest run --config vitest.config.ts",
+ "test:unit": "vitest run --config vitest.config.ts",
+ "test:integration": "vitest run --config vitest.integration.config.ts",
"test:watch": "vitest --config vitest.config.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
diff --git a/apps/api/vitest.integration.config.ts b/apps/api/vitest.integration.config.ts
new file mode 100644
index 000000000..13457a673
--- /dev/null
+++ b/apps/api/vitest.integration.config.ts
@@ -0,0 +1,15 @@
+import { defineConfig } from "vitest/config";
+
+export default defineConfig({
+ test: {
+ environment: "node",
+ include: ["../../tests/api-integration/**/*.test.ts"],
+ setupFiles: ["../../tests/api-integration/setup.ts"],
+ coverage: {
+ enabled: false,
+ },
+ },
+ esbuild: {
+ target: "node18",
+ },
+});
diff --git a/package.json b/package.json
index 840926fbf..22d60d5e3 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"dev": "turbo dev",
"lint": "turbo lint",
"test": "turbo test",
+ "test:integration": "pnpm --filter @kaneo/api test:integration",
"prepare": "husky"
},
"devDependencies": {
diff --git a/tests/api-integration/config.test.ts b/tests/api-integration/config.test.ts
new file mode 100644
index 000000000..d40ee79b7
--- /dev/null
+++ b/tests/api-integration/config.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from "vitest";
+import { createApp } from "../../apps/api/src/index";
+
+describe("API integration: config", () => {
+ it("returns the public config shape", async () => {
+ const { app } = createApp();
+
+ const response = await app.request("/api/config");
+
+ expect(response.status).toBe(200);
+ const payload = (await response.json()) as Record<string, unknown>;
+
+ expect(payload).toMatchObject({
+ disableRegistration: false,
+ disablePasswordRegistration: false,
+ isDemoMode: false,
+ hasGuestAccess: true,
+ });
+ expect(payload).toSatisfy((value: Record<string, unknown>) =>
+ [
+ "hasSmtp",
+ "hasGithubSignIn",
+ "hasGoogleSignIn",
+ "hasDiscordSignIn",
+ "hasCustomOAuth",
+ ].every((key) => typeof value[key] === "boolean"),
+ );
+ });
+});
diff --git a/tests/api-integration/health.test.ts b/tests/api-integration/health.test.ts
new file mode 100644
index 000000000..bc7c47fcd
--- /dev/null
+++ b/tests/api-integration/health.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, it } from "vitest";
+import { createApp } from "../../apps/api/src/index";
+
+describe("API integration: health", () => {
+ it("responds with ok on /api/health", async () => {
+ const { app } = createApp();
+
+ const response = await app.request("/api/health");
+
+ expect(response.status).toBe(200);
+ await expect(response.json()).resolves.toEqual({ status: "ok" });
+ });
+});
diff --git a/tests/api-integration/setup.ts b/tests/api-integration/setup.ts
new file mode 100644
index 000000000..ea0ce746d
--- /dev/null
+++ b/tests/api-integration/setup.ts
@@ -0,0 +1,29 @@
+import { vi } from "vitest";
+
+vi.mock("dotenv-mono", () => ({
+ config: () => ({}),
+}));
+
+process.env.NODE_ENV = "test";
+process.env.AUTH_SECRET = "test-secret-with-at-least-32-chars";
+process.env.DATABASE_URL =
+ "postgresql://postgres:postgres@localhost:5432/kaneo_test";
+process.env.KANEO_API_URL = "http://localhost:1337";
+process.env.KANEO_CLIENT_URL = "http://localhost:5173";
+process.env.DISABLE_GUEST_ACCESS = "false";
+process.env.DISABLE_REGISTRATION = "false";
+process.env.DISABLE_PASSWORD_REGISTRATION = "false";
+process.env.DEMO_MODE = "false";
+process.env.SMTP_HOST = "";
+process.env.SMTP_PORT = "";
+process.env.SMTP_SECURE = "";
+process.env.SMTP_USER = "";
+process.env.SMTP_PASSWORD = "";
+process.env.GITHUB_CLIENT_ID = "";
+process.env.GITHUB_CLIENT_SECRET = "";
+process.env.GOOGLE_CLIENT_ID = "";
+process.env.GOOGLE_CLIENT_SECRET = "";
+process.env.DISCORD_CLIENT_ID = "";
+process.env.DISCORD_CLIENT_SECRET = "";
+process.env.CUSTOM_OAUTH_CLIENT_ID = "";
+process.env.CUSTOM_OAUTH_CLIENT_SECRET = "";