This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/commands/collectionImporter.test.js

91 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-12-18 05:19:31 +00:00
// @flow
import path from "path";
import File from "formidable/lib/file";
import { Attachment, Document, Collection } from "../models";
2020-12-18 05:19:31 +00:00
import { buildUser } from "../test/factories";
import { flushdb } from "../test/support";
import collectionImporter from "./collectionImporter";
2020-12-18 05:19:31 +00:00
jest.mock("../utils/s3");
beforeEach(() => flushdb());
describe("collectionImporter", () => {
2020-12-18 05:19:31 +00:00
const ip = "127.0.0.1";
it("should import documents in outline format", async () => {
const user = await buildUser();
const name = "outline.zip";
const file = new File({
name,
type: "application/zip",
path: path.resolve(__dirname, "..", "test", "fixtures", name),
});
const response = await collectionImporter({
2020-12-18 05:19:31 +00:00
type: "outline",
user,
file,
ip,
});
2020-12-24 18:18:53 +00:00
2020-12-27 07:12:22 +00:00
expect(response.collections.length).toEqual(1);
expect(response.documents.length).toEqual(8);
expect(response.attachments.length).toEqual(6);
expect(await Collection.count()).toEqual(1);
expect(await Document.count()).toEqual(8);
expect(await Attachment.count()).toEqual(6);
});
it("should throw an error with corrupt zip", async () => {
const user = await buildUser();
const name = "corrupt.zip";
const file = new File({
name,
type: "application/zip",
path: path.resolve(__dirname, "..", "test", "fixtures", name),
});
let error;
try {
await collectionImporter({
type: "outline",
user,
file,
ip,
});
} catch (err) {
error = err;
}
expect(error && error.message).toBeTruthy();
});
it("should throw an error with empty zip", async () => {
const user = await buildUser();
const name = "empty.zip";
const file = new File({
name,
type: "application/zip",
path: path.resolve(__dirname, "..", "test", "fixtures", name),
});
let error;
try {
await collectionImporter({
type: "outline",
user,
file,
ip,
});
} catch (err) {
error = err;
}
expect(error && error.message).toBe(
"Uploaded file does not contain importable documents"
);
2020-12-18 05:19:31 +00:00
});
});