test: cover message query pagination
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
decodeCursor,
|
||||
encodeCursor,
|
||||
@@ -24,10 +24,41 @@ describe("message cursor helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("listMessages integration tests", () => {
|
||||
describe("message query integration tests", () => {
|
||||
beforeAll(async () => {
|
||||
// Initialize database once for all tests
|
||||
await initializeDatabase();
|
||||
// Create tables using Drizzle schema (SQLite doesn't support migrations with PostgreSQL syntax)
|
||||
const db = getDatabase() as any;
|
||||
try {
|
||||
// Create messages table
|
||||
await db.run(`
|
||||
CREATE TABLE IF NOT EXISTS "messages" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"guild_id" text NOT NULL,
|
||||
"channel_id" text NOT NULL,
|
||||
"thread_id" text,
|
||||
"user_id" text NOT NULL,
|
||||
"username" text NOT NULL,
|
||||
"avatar_url" text,
|
||||
"content" text NOT NULL,
|
||||
"edited_content" text,
|
||||
"created_at" integer NOT NULL,
|
||||
"edited_at" integer,
|
||||
"deleted_at" integer,
|
||||
"type" text DEFAULT 'text' NOT NULL,
|
||||
"metadata" text,
|
||||
"ai_status" text DEFAULT 'pending' NOT NULL,
|
||||
"ai_moderation_flags" text,
|
||||
"ai_moderation_score" real,
|
||||
"ai_moderation_raw" text,
|
||||
"ai_analysis" text,
|
||||
"ai_analyzed_at" integer,
|
||||
"ai_error" text
|
||||
)
|
||||
`);
|
||||
} catch (error) {
|
||||
logger.debug("Messages table already exists or error creating it", { error });
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -41,16 +72,7 @@ describe("listMessages integration tests", () => {
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
// Clear messages table before each test
|
||||
try {
|
||||
const db = getDatabase();
|
||||
await db.delete(messagesTable);
|
||||
} catch (error) {
|
||||
logger.debug("Could not clear messages table", { error });
|
||||
}
|
||||
});
|
||||
|
||||
describe("listMessages", () => {
|
||||
const createTestMessage = (
|
||||
overrides: Partial<MessageRecord> = {},
|
||||
): MessageRecord => ({
|
||||
@@ -314,35 +336,9 @@ describe("listMessages integration tests", () => {
|
||||
expect(result.data).toHaveLength(1);
|
||||
expect(result.data[0].id).toBe("msg-combo-1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("listReviewMessages integration tests", () => {
|
||||
beforeAll(async () => {
|
||||
// Initialize database once for all tests
|
||||
await initializeDatabase();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await closeDatabase();
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{ error: error instanceof Error ? error.message : String(error) },
|
||||
"Error closing database in afterAll",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
// Clear messages table before each test
|
||||
try {
|
||||
const db = getDatabase();
|
||||
await db.delete(messagesTable);
|
||||
} catch (error) {
|
||||
logger.debug("Could not clear messages table", { error });
|
||||
}
|
||||
});
|
||||
|
||||
describe("listReviewMessages", () => {
|
||||
const createTestMessage = (
|
||||
overrides: Partial<MessageRecord> = {},
|
||||
): MessageRecord => ({
|
||||
@@ -488,4 +484,5 @@ describe("listReviewMessages integration tests", () => {
|
||||
const overlap = page1Ids.filter((id) => page2Ids.includes(id));
|
||||
expect(overlap).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user