refactor: update database index tests to use DrizzleClient.execute for raw SQL queries.
Some checks failed
Deploy to Production / test (push) Failing after 29s
Deploy to Production / build (push) Has been skipped
Deploy to Production / deploy (push) Has been skipped

This commit is contained in:
syntaxbullet
2026-01-30 16:22:29 +01:00
parent 119301f1c3
commit bb823c86c1

View File

@@ -1,42 +1,43 @@
import { expect, test, describe } from "bun:test";
import { postgres } from "./DrizzleClient";
import { DrizzleClient } from "./DrizzleClient";
import { sql } from "drizzle-orm";
describe("Database Indexes", () => {
test("should have indexes on users table", async () => {
const result = await postgres`
const result = await DrizzleClient.execute(sql`
SELECT indexname FROM pg_indexes
WHERE tablename = 'users'
`;
const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
`);
const indexNames = result.map(r => r.indexname);
expect(indexNames).toContain("users_balance_idx");
expect(indexNames).toContain("users_level_xp_idx");
});
test("should have index on transactions table", async () => {
const result = await postgres`
const result = await DrizzleClient.execute(sql`
SELECT indexname FROM pg_indexes
WHERE tablename = 'transactions'
`;
const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
`);
const indexNames = result.map(r => r.indexname);
expect(indexNames).toContain("transactions_created_at_idx");
});
test("should have indexes on moderation_cases table", async () => {
const result = await postgres`
const result = await DrizzleClient.execute(sql`
SELECT indexname FROM pg_indexes
WHERE tablename = 'moderation_cases'
`;
const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
`);
const indexNames = result.map(r => r.indexname);
expect(indexNames).toContain("moderation_cases_user_id_idx");
expect(indexNames).toContain("moderation_cases_case_id_idx");
});
test("should have indexes on user_timers table", async () => {
const result = await postgres`
const result = await DrizzleClient.execute(sql`
SELECT indexname FROM pg_indexes
WHERE tablename = 'user_timers'
`;
const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
`);
const indexNames = result.map(r => r.indexname);
expect(indexNames).toContain("user_timers_expires_at_idx");
expect(indexNames).toContain("user_timers_lookup_idx");
});