Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dms-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roshan Suvarnkar
dms-service
Commits
ae6f778e
Commit
ae6f778e
authored
1 month ago
by
Manjunath Kumar
Browse files
Options
Downloads
Patches
Plain Diff
fetch-document-by-id-review-sonar-coverage
parent
57c15b26
No related branches found
No related tags found
1 merge request
!3
fetchdocumentById in dms
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/document/document.service.spec.ts
+30
-0
30 additions, 0 deletions
src/document/document.service.spec.ts
with
30 additions
and
0 deletions
src/document/document.service.spec.ts
+
30
−
0
View file @
ae6f778e
...
...
@@ -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
'
);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment