Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ const mockDb = {
findFirst: jest.fn(),
findUnique: jest.fn(),
create: jest.fn(),
createMany: jest.fn(),
delete: jest.fn(),
count: jest.fn(),
},
vendor: {
findMany: jest.fn(),
findFirst: jest.fn(),
count: jest.fn(),
},
member: {
findFirst: jest.fn(),
findMany: jest.fn(),
},
attachment: {
findMany: jest.fn(),
},
$transaction: jest.fn((fn: (tx: typeof mockDb) => Promise<unknown>) => fn(mockDb)),
};

jest.mock('@db', () => ({
Expand All @@ -46,6 +57,7 @@ describe('OffboardingChecklistService', () => {
getAttachments: jest.fn(),
uploadAttachment: jest.fn(),
deleteAttachment: jest.fn(),
getPresignedDownloadUrl: jest.fn().mockResolvedValue('https://signed-url.example.com'),
};

let service: OffboardingChecklistService;
Expand Down Expand Up @@ -146,8 +158,8 @@ describe('OffboardingChecklistService', () => {
completedBy: { id: 'usr_1', name: 'Test User' },
},
]);
mockAttachmentsService.getAttachments.mockResolvedValue([
{ id: 'att_1', name: 'evidence.pdf' },
mockDb.attachment.findMany.mockResolvedValue([
{ id: 'att_1', name: 'evidence.pdf', url: 's3://bucket/key', entityId: 'occ_1' },
]);

const result = await service.getMemberChecklist('org_1', 'mem_1');
Expand Down Expand Up @@ -423,17 +435,19 @@ describe('OffboardingChecklistService', () => {
describe('getAccessRevocations', () => {
it('returns vendor list with revocation status', async () => {
mockDb.vendor.findMany.mockResolvedValue([
{ id: 'vnd_1', name: 'Slack' },
{ id: 'vnd_2', name: 'AWS' },
{ id: 'vnd_1', name: 'Slack', website: null, logoUrl: null },
{ id: 'vnd_2', name: 'AWS', website: null, logoUrl: null },
]);
mockDb.offboardingAccessRevocation.findMany.mockResolvedValue([
{
id: 'oar_1',
vendorId: 'vnd_1',
revokedBy: { id: 'usr_1', name: 'Jane', email: 'jane@test.com' },
revokedAt: new Date(),
notes: null,
},
]);
mockDb.attachment.findMany.mockResolvedValue([]);

const result = await service.getAccessRevocations('org_1', 'mem_1');

Expand All @@ -446,6 +460,7 @@ describe('OffboardingChecklistService', () => {
it('returns empty when no vendors exist', async () => {
mockDb.vendor.findMany.mockResolvedValue([]);
mockDb.offboardingAccessRevocation.findMany.mockResolvedValue([]);
mockDb.attachment.findMany.mockResolvedValue([]);

const result = await service.getAccessRevocations('org_1', 'mem_1');

Expand All @@ -457,6 +472,7 @@ describe('OffboardingChecklistService', () => {

describe('revokeVendorAccess', () => {
it('creates revocation record', async () => {
mockDb.member.findFirst.mockResolvedValue({ id: 'mem_1', organizationId: 'org_1' });
mockDb.vendor.findFirst.mockResolvedValue({ id: 'vnd_1' });
mockDb.offboardingAccessRevocation.findUnique.mockResolvedValue(null);
mockDb.offboardingAccessRevocation.create.mockResolvedValue({
Expand All @@ -479,6 +495,7 @@ describe('OffboardingChecklistService', () => {
});

it('throws if vendor not found', async () => {
mockDb.member.findFirst.mockResolvedValue({ id: 'mem_1', organizationId: 'org_1' });
mockDb.vendor.findFirst.mockResolvedValue(null);

await expect(
Expand All @@ -492,6 +509,7 @@ describe('OffboardingChecklistService', () => {
});

it('throws if already revoked', async () => {
mockDb.member.findFirst.mockResolvedValue({ id: 'mem_1', organizationId: 'org_1' });
mockDb.vendor.findFirst.mockResolvedValue({ id: 'vnd_1' });
mockDb.offboardingAccessRevocation.findUnique.mockResolvedValue({
id: 'oar_1',
Expand Down
32 changes: 26 additions & 6 deletions apps/api/src/tasks/evidence-export/evidence-data-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ export async function getAutomationHeaders({
throw new NotFoundException('Task not found');
}

const [appRuns, customRuns] = await Promise.all([
db.integrationCheckRun.findMany({
const HEADER_BATCH = 500;
const appRuns: AppRunHeader[] = [];
let appCursor: string | undefined;
while (true) {
const batch = await db.integrationCheckRun.findMany({
where: { taskId },
select: {
id: true,
checkId: true,
checkName: true,
status: true,
Expand All @@ -140,21 +144,37 @@ export async function getAutomationHeaders({
},
},
orderBy: { createdAt: 'desc' },
}),
db.evidenceAutomationRun.findMany({
take: HEADER_BATCH,
...(appCursor ? { cursor: { id: appCursor }, skip: 1 } : {}),
});
appRuns.push(...batch);
if (batch.length < HEADER_BATCH) break;
appCursor = batch[batch.length - 1]!.id;
}

const customRuns: CustomRunHeader[] = [];
let customCursor: string | undefined;
while (true) {
const batch = await db.evidenceAutomationRun.findMany({
where: {
evidenceAutomation: { taskId },
version: { not: null },
},
select: {
id: true,
status: true,
evaluationStatus: true,
createdAt: true,
evidenceAutomation: { select: { id: true, name: true } },
},
orderBy: { createdAt: 'desc' },
}),
]);
take: HEADER_BATCH,
...(customCursor ? { cursor: { id: customCursor }, skip: 1 } : {}),
});
customRuns.push(...batch);
if (batch.length < HEADER_BATCH) break;
customCursor = batch[batch.length - 1]!.id;
}

return {
taskId: task.id,
Expand Down
Loading