Skip to content
Snippets Groups Projects
Commit ae6f778e authored by Manjunath Kumar's avatar Manjunath Kumar
Browse files

fetch-document-by-id-review-sonar-coverage

parent 57c15b26
No related branches found
No related tags found
1 merge request!3fetchdocumentById in dms
......@@ -186,5 +186,35 @@ describe('DocumentService', () => {
jest.spyOn(service['prisma'].documents, 'findUnique').mockResolvedValue(null);
await expect(service.fetchDocument({ id: 'not-found-id' })).rejects.toThrow('980');
});
it('should return presigned url for FILENET if alternate branch is hit', async () => {
// This mock matches the FILENET + document_link branch in the service
mockPrisma.documents.findUnique.mockResolvedValue({
document_id: '3',
document_name: 'filenet-alt.pdf',
source: 'FILENET',
document_link: 'doc-link',
});
jest.spyOn(service, 'logInsertToDocumentsAuditLogs').mockResolvedValue(true);
const result = await service.fetchDocument({ id: '3' });
console.log('DEBUG result:', result); // <-- Add this line
expect(result.base64).toBeDefined();
expect(result.base64?.fileName).toBe('filenet-alt.pdf');
expect(result.base64?.mimeType).toBe('application/pdf');
expect(result.base64?.content).toBeDefined();
expect(service.logInsertToDocumentsAuditLogs).toHaveBeenCalled();
});
it('should throw original error if logInsertToDocumentsAuditLogs fails', async () => {
mockPrisma.documents.findUnique.mockResolvedValue({
document_id: '4',
document_name: 'fail-log.pdf',
source: 'FILENET',
document_link: 'doc-link',
});
jest.spyOn(service, 'logInsertToDocumentsAuditLogs').mockRejectedValue(new Error('log failed'));
await expect(service.fetchDocument({ id: '4' }))
.rejects.toThrow('log failed');
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment