Skip to content

Commit

Permalink
add test to check that docs refer to existing attachments in zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomás Ciccola authored and EvanHahn committed Nov 20, 2024
1 parent 78972ec commit 555f84d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"eslint": "^9.15.0",
"globals": "^15.12.0",
"npm-run-all": "^4.1.5",
"mime": "^4.0.4",
"patch-package": "^8.0.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3",
Expand Down
18 changes: 17 additions & 1 deletion test/writer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import test from "node:test";
import { join, relative } from 'node:path'
import { join, relative, basename } from 'node:path'
import { json } from 'node:stream/consumers';
import fs from 'node:fs/promises'
import assert from "node:assert/strict";
import yauzl from 'yauzl-promise'
import mime from 'mime/lite';
import MLEFWriter from "../src/writer.js";

// add testing of links of docs to attachments
// 1. if there's a ref, check that file exists (on the three folders?)
// 2. check that there is no image unreferenced? (not that important)

test("loading and packing a db into a zip", async (t) => {
const dbName = 'db1'
const path = new URL(join('./fixture', dbName), import.meta.url).pathname;
Expand Down Expand Up @@ -55,6 +60,17 @@ test("loading and packing a db into a zip", async (t) => {
'the docs zipped matches the original'
)

const attachmentsRef = docsInZip.flatMap(doc => doc.attachments)
const attachmentsInZipAsRefs = attachmentsInZip
.filter(attachment => attachment.match(/original/))
.map(attachment => ({ id: basename(attachment), type: mime.getType(attachment) }))

assert.deepEqual(
new Set(attachmentsRef),
new Set(attachmentsInZipAsRefs),
'references to attachments in docs link to images that exist'
)

t.after(async () => {
await teardown([out, outDefaultPath])
zip.close()
Expand Down

0 comments on commit 555f84d

Please sign in to comment.