fix(test): Add ENCRYPTION_KEY to bridge.module.spec.ts and fix API lint errors
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2026-02-07 17:33:32 -06:00
parent b9e1e3756e
commit 4552c2c460
6 changed files with 332 additions and 0 deletions

View File

@@ -24,6 +24,10 @@ describe("CredentialsService", () => {
update: vi.fn(),
delete: vi.fn(),
},
activityLog: {
findMany: vi.fn(),
count: vi.fn(),
},
};
const mockActivityService = {
@@ -479,4 +483,141 @@ describe("CredentialsService", () => {
);
});
});
describe("getAuditLog", () => {
const mockAuditLogs = [
{
id: "log-1",
action: ActivityAction.CREDENTIAL_ACCESSED,
entityId: mockCredentialId,
createdAt: new Date("2024-01-15T10:00:00Z"),
details: { name: "GitHub Token", provider: "github" },
user: {
id: mockUserId,
name: "John Doe",
email: "john@example.com",
},
},
{
id: "log-2",
action: ActivityAction.CREDENTIAL_CREATED,
entityId: mockCredentialId,
createdAt: new Date("2024-01-10T09:00:00Z"),
details: { name: "GitHub Token", provider: "github" },
user: {
id: mockUserId,
name: "John Doe",
email: "john@example.com",
},
},
];
it("should return paginated audit logs", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue(mockAuditLogs);
mockPrismaService.activityLog.count.mockResolvedValue(2);
const result = await service.getAuditLog(mockWorkspaceId, {
page: 1,
limit: 20,
});
expect(result.data).toHaveLength(2);
expect(result.meta.total).toBe(2);
expect(result.meta.page).toBe(1);
expect(result.meta.limit).toBe(20);
expect(result.meta.totalPages).toBe(1);
});
it("should filter by credentialId", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue([mockAuditLogs[0]]);
mockPrismaService.activityLog.count.mockResolvedValue(1);
await service.getAuditLog(mockWorkspaceId, {
credentialId: mockCredentialId,
page: 1,
limit: 20,
});
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.where.entityId).toBe(mockCredentialId);
});
it("should filter by action type", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue([mockAuditLogs[0]]);
mockPrismaService.activityLog.count.mockResolvedValue(1);
await service.getAuditLog(mockWorkspaceId, {
action: ActivityAction.CREDENTIAL_ACCESSED,
page: 1,
limit: 20,
});
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.where.action).toBe(ActivityAction.CREDENTIAL_ACCESSED);
});
it("should filter by date range", async () => {
const startDate = new Date("2024-01-10T00:00:00Z");
const endDate = new Date("2024-01-15T23:59:59Z");
mockPrismaService.activityLog.findMany.mockResolvedValue(mockAuditLogs);
mockPrismaService.activityLog.count.mockResolvedValue(2);
await service.getAuditLog(mockWorkspaceId, {
startDate,
endDate,
page: 1,
limit: 20,
});
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.where.createdAt.gte).toBe(startDate);
expect(callArgs.where.createdAt.lte).toBe(endDate);
});
it("should handle pagination correctly", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue([mockAuditLogs[0]]);
mockPrismaService.activityLog.count.mockResolvedValue(25);
const result = await service.getAuditLog(mockWorkspaceId, {
page: 2,
limit: 20,
});
expect(result.meta.page).toBe(2);
expect(result.meta.limit).toBe(20);
expect(result.meta.totalPages).toBe(2);
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.skip).toBe(20); // (2 - 1) * 20
expect(callArgs.take).toBe(20);
});
it("should order by createdAt descending", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue(mockAuditLogs);
mockPrismaService.activityLog.count.mockResolvedValue(2);
await service.getAuditLog(mockWorkspaceId, {
page: 1,
limit: 20,
});
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.orderBy).toEqual({ createdAt: "desc" });
});
it("should always filter by CREDENTIAL entityType", async () => {
mockPrismaService.activityLog.findMany.mockResolvedValue([]);
mockPrismaService.activityLog.count.mockResolvedValue(0);
await service.getAuditLog(mockWorkspaceId, {
page: 1,
limit: 20,
});
const callArgs = mockPrismaService.activityLog.findMany.mock.calls[0][0];
expect(callArgs.where.entityType).toBe(EntityType.CREDENTIAL);
expect(callArgs.where.workspaceId).toBe(mockWorkspaceId);
});
});
});