test: Add additional tests and input validation

This commit is contained in:
Tom Moor
2020-12-28 15:30:01 -08:00
parent b932457fd3
commit 2787e56de3
5 changed files with 68 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ import invariant from "invariant";
import { values, keys } from "lodash";
import uuid from "uuid";
import { parseOutlineExport } from "../../shared/utils/zip";
import { InvalidRequestError } from "../errors";
import { FileImportError } from "../errors";
import { Attachment, Document, Collection, User } from "../models";
import attachmentCreator from "./attachmentCreator";
import documentCreator from "./documentCreator";
@@ -34,7 +34,13 @@ export default async function documentBatchImporter({
try {
items = await await parseOutlineExport(zipData);
} catch (err) {
throw new InvalidRequestError(err.message);
throw new FileImportError(err.message);
}
if (!items.filter((item) => item.type === "document").length) {
throw new FileImportError(
"Uploaded file does not contain importable documents"
);
}
// store progress and pointers
@@ -96,6 +102,8 @@ export default async function documentBatchImporter({
ip,
});
await fs.promises.unlink(tmpFilePath);
// must be a nested document, find and reference the parent document
let parentDocumentId;
if (item.depth > 1) {