Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./src/__tests__/setup.ts"]
2 changes: 2 additions & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const knipConfig: KnipConfig = {
"src/instrumentation.ts",
// Drizzle schema exports (relations, Select/Insert types) for ORM use
"src/lib/db/schema/**",
// Test setup preloaded via bunfig.toml
"src/__tests__/setup.ts",
],
ignoreDependencies: [
// OpenTelemetry deps used by instrumentation.ts (loaded via --import)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"format": "biome format --write",
"check": "biome check",
"knip": "knip-bun",
"test": "bun test",
"db:setup": "bun src/scripts/db/setupDatabase.ts",
"db:check": "bun --env-file .env.local drizzle-kit check --config src/lib/config/drizzle.config.ts",
"db:generate": "bun --env-file .env.local drizzle-kit generate --config src/lib/config/drizzle.config.ts",
Expand All @@ -39,7 +40,7 @@
"@graphile/pg-aggregates": "^0.2.0-rc.1",
"@graphile/simplify-inflection": "^8.0.0-rc.2",
"@graphql-yoga/plugin-disable-introspection": "^2.19.0",
"@omnidotdev/providers": "github:omnidotdev/providers#316498f",
"@omnidotdev/providers": "github:omnidotdev/providers#f1e7db9",
"@omnidotdev/search": "github:omnidotdev/search",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.68.0",
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Global test setup for Bun test runner.
*
* Automatically loaded via bunfig.toml preload.
* Uses dynamic import to avoid eagerly loading `lib/db/db`, which
* would break test isolation when other files mock that module.
*/

import { afterAll } from "bun:test";

afterAll(async () => {
try {
const { pgPool } = await import("lib/db/db");
await pgPool.end();
} catch {
// Module may be mocked in unit tests
}
});
61 changes: 61 additions & 0 deletions src/__tests__/userPreferenceSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { describe, expect, it } from "bun:test";

import { getTableColumns, getTableName } from "drizzle-orm";

import { userPreferences } from "lib/db/schema/userPreference.table";

import type {
InsertUserPreference,
SelectUserPreference,
} from "lib/db/schema/userPreference.table";

describe("userPreferences schema", () => {
const columns = getTableColumns(userPreferences);

it("maps to the user_preference table", () => {
expect(getTableName(userPreferences)).toBe("user_preference");
});

describe("pinOrder column", () => {
it("exists in the schema", () => {
expect(columns.pinOrder).toBeDefined();
});

it("is an integer type", () => {
expect(columns.pinOrder.dataType).toBe("number");
expect(columns.pinOrder.columnType).toBe("PgInteger");
});

it("is nullable (no notNull constraint)", () => {
expect(columns.pinOrder.notNull).toBe(false);
});

it("has no default value", () => {
expect(columns.pinOrder.hasDefault).toBe(false);
});
});

describe("type inference", () => {
it("allows pinOrder to be null on select", () => {
// Type-level assertion: pinOrder is number | null
type Check = SelectUserPreference extends { pinOrder: number | null }
? true
: false;
expect(true satisfies Check).toBe(true);
});

it("allows pinOrder to be omitted on insert", () => {
// Type-level assertion: pinOrder is optional
type Check = InsertUserPreference extends { pinOrder?: number | null }
? true
: false;
expect(true satisfies Check).toBe(true);
});
});

describe("does not have a pinned boolean column", () => {
it("has no pinned column", () => {
expect((columns as Record<string, unknown>).pinned).toBeUndefined();
});
});
});
1 change: 1 addition & 0 deletions src/generated/drizzle/0050_pin_order.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "user_preference" ADD COLUMN "pin_order" integer;
Loading
Loading