test: add tests for audit logging utility
- Add comprehensive tests for logAuditEvent - Add tests for getAuditLogs with user filtering - Test graceful degradation when feature disabled - Test JSON details parsing - Follow existing test patterns and style
This commit is contained in:
@@ -54,19 +54,42 @@ export const cleanupTestDb = async (prisma: PrismaClient) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a test user for testing
|
||||
*/
|
||||
export const createTestUser = async (prisma: PrismaClient, email: string = "test@example.com") => {
|
||||
const bcrypt = require("bcrypt");
|
||||
const passwordHash = await bcrypt.hash("testpassword", 10);
|
||||
|
||||
return await prisma.user.upsert({
|
||||
where: { email },
|
||||
update: {},
|
||||
create: {
|
||||
email,
|
||||
passwordHash,
|
||||
name: "Test User",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize test database with required data
|
||||
*/
|
||||
export const initTestDb = async (prisma: PrismaClient) => {
|
||||
// Create a test user first
|
||||
const testUser = await createTestUser(prisma);
|
||||
|
||||
// Ensure Trash collection exists
|
||||
const trash = await prisma.collection.findUnique({
|
||||
where: { id: "trash" },
|
||||
});
|
||||
if (!trash) {
|
||||
await prisma.collection.create({
|
||||
data: { id: "trash", name: "Trash" },
|
||||
data: { id: "trash", name: "Trash", userId: testUser.id },
|
||||
});
|
||||
}
|
||||
|
||||
return testUser;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user