-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blake Holifield
committed
Jul 12, 2024
1 parent
7ffe8de
commit 466f67b
Showing
2 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import PdfCache, { PDFComponent, PdfStatus } from './pdfCache'; | ||
|
||
describe('Pdf Cache updates', () => { | ||
const pdfCache = PdfCache.getInstance(); | ||
const cache: PDFComponent = { | ||
status: PdfStatus.Failed, | ||
filepath: '', | ||
collectionId: '7855a523-fc64-4e51-910a-b1ff3918b440', | ||
componentId: 'fb99bc16-4cdc-4200-afbf-479d904ee987', | ||
numPages: 0, | ||
error: 'oops', | ||
}; | ||
const baseId = '7855a523-fc64-4e51-910a-b1ff3918b440'; | ||
pdfCache.addToCollection(baseId, cache); | ||
|
||
it('should return a valid collection', () => { | ||
pdfCache.verifyCollection(baseId); | ||
const coll = pdfCache.getCollection(baseId); | ||
expect(coll.components.length).toBe(1); | ||
expect(coll.components[0].componentId).toBe( | ||
'fb99bc16-4cdc-4200-afbf-479d904ee987' | ||
); | ||
}); | ||
|
||
it('should validate a generated collection with all expected components', () => { | ||
const comp: PDFComponent = { | ||
status: PdfStatus.Generated, | ||
filepath: 'blah', | ||
collectionId: '9855a523-fc64-4e51-910a-b1ff3918b440', | ||
componentId: 'fb99bc16-4cdc-4200-afbf-479d904ee987', | ||
numPages: 5, | ||
}; | ||
const another: PDFComponent = { | ||
status: PdfStatus.Generated, | ||
filepath: 'blah', | ||
collectionId: '9855a523-fc64-4e51-910a-b1ff3918b440', | ||
componentId: 'aaaaaaa-4cdc-4200-afbf-479d904ee987', | ||
numPages: 5, | ||
}; | ||
const compId = comp.collectionId; | ||
pdfCache.addToCollection(compId, comp); | ||
pdfCache.setExpectedLength(compId, 2); | ||
pdfCache.verifyCollection(compId); | ||
const unfinished = pdfCache.getCollection(compId); | ||
expect(unfinished.expectedLength).toBe(2); | ||
expect(unfinished.components.length).toBe(1); | ||
expect(unfinished.status).toBe(PdfStatus.Generating); | ||
pdfCache.addToCollection(compId, another); | ||
pdfCache.verifyCollection(compId); | ||
const finished = pdfCache.getCollection(compId); | ||
expect(finished.expectedLength).toBe(2); | ||
expect(finished.components.length).toBe(2); | ||
expect(finished.status).toBe(PdfStatus.Generated); | ||
}); | ||
|
||
it('should invalidate a failed collection', () => { | ||
pdfCache.verifyCollection(baseId); | ||
const coll = pdfCache.getCollection(baseId); | ||
expect(coll.components.length).toBe(1); | ||
expect(coll.status).toBe('Failed'); | ||
expect(coll.error).toBe('oops'); | ||
}); | ||
|
||
it('should reset a collection with no expectedLength', () => { | ||
const comp: PDFComponent = { | ||
status: PdfStatus.Generating, | ||
filepath: 'blah', | ||
collectionId: '9855a523-fc64-4e51-910a-b1ff3918b440', | ||
componentId: 'fb99bc16-4cdc-4200-afbf-479d904ee987', | ||
numPages: 5, | ||
}; | ||
const compId = comp.collectionId; | ||
pdfCache.addToCollection(compId, comp); | ||
pdfCache.verifyCollection(compId); | ||
const unfinished = pdfCache.getCollection(compId); | ||
expect(unfinished.expectedLength).toBe(0); | ||
expect(unfinished.components.length).toBe(1); | ||
expect(unfinished.status).toBe(PdfStatus.Generating); | ||
}); | ||
|
||
it('should reset a collection with no expectedLength', () => { | ||
const comp: PDFComponent = { | ||
status: PdfStatus.Generating, | ||
filepath: 'blah', | ||
collectionId: '9855a523-fc64-4e51-910a-b1ff3918b440', | ||
componentId: 'fb99bc16-4cdc-4200-afbf-479d904ee987', | ||
numPages: 5, | ||
}; | ||
const compId = comp.collectionId; | ||
pdfCache.addToCollection(compId, comp); | ||
pdfCache.verifyCollection(compId); | ||
const unfinished = pdfCache.getCollection(compId); | ||
expect(unfinished.expectedLength).toBe(0); | ||
expect(unfinished.components.length).toBe(1); | ||
expect(unfinished.status).toBe(PdfStatus.Generating); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters