forked from ustaxes/UsTaxes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to make sure pdfs are actually generated
- Loading branch information
1 parent
914cd3a
commit e228e6d
Showing
13 changed files
with
159 additions
and
136 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
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,36 @@ | ||
import { PDFDocument } from 'pdf-lib' | ||
import { | ||
FileDownloader, | ||
PDFDownloader | ||
} from 'ustaxes/core/pdfFiller/pdfHandler' | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
import { TaxYear } from 'ustaxes/data' | ||
|
||
const localPath = (url: string) => path.join(__dirname, '../../../public', url) | ||
|
||
export const localFiles: FileDownloader<Uint8Array> = ( | ||
url: string | ||
): Promise<Uint8Array> => fs.readFile(localPath(url)) | ||
|
||
const compiledPDFs: { [key: string]: PDFDocument } = {} | ||
|
||
export const localPDFs = | ||
(y: TaxYear): PDFDownloader => | ||
async (url: string): Promise<PDFDocument> => { | ||
const fileUrl = `/forms/${y}/${url}` | ||
|
||
const lookedUpAt = localPath(fileUrl) | ||
|
||
if (lookedUpAt in compiledPDFs) { | ||
return compiledPDFs[lookedUpAt] | ||
} | ||
|
||
const bytes = await localFiles(fileUrl) | ||
|
||
const pdf = await PDFDocument.load(bytes.buffer) | ||
|
||
compiledPDFs[lookedUpAt] = pdf | ||
|
||
return pdf | ||
} |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.