chromiumly 2.3.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +4 -6
- package/dist/chromium/converters/html.converter.js +3 -4
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +5 -7
- package/dist/chromium/converters/markdown.converter.js +3 -6
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +3 -5
- package/dist/chromium/converters/url.converter.js +1 -1
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/converter.types.d.ts +3 -5
- package/dist/chromium/utils/converter.utils.d.ts +3 -1
- package/dist/chromium/utils/converter.utils.js +26 -11
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +3 -0
- package/dist/common/types.js +3 -0
- package/dist/common/types.js.map +1 -0
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +3 -4
- package/dist/libre-office/utils/libre-office.utils.js +18 -9
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.js +3 -3
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +2 -3
- package/dist/pdf-engines/utils/engine.utils.js +17 -8
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +7 -7
- package/src/chromium/converters/converter.ts +5 -5
- package/src/chromium/converters/html.converter.ts +54 -56
- package/src/chromium/converters/markdown.converter.ts +57 -60
- package/src/chromium/converters/tests/html.converter.test.ts +121 -126
- package/src/chromium/converters/tests/markdown.converter.test.ts +132 -139
- package/src/chromium/converters/tests/url.converter.test.ts +114 -123
- package/src/chromium/converters/url.converter.ts +55 -57
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/converter.types.ts +27 -27
- package/src/chromium/utils/converter.utils.ts +141 -129
- package/src/chromium/utils/tests/converter.utils.test.ts +315 -280
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +16 -16
- package/src/common/index.ts +3 -2
- package/src/common/tests/gotenberg.utils.test.ts +54 -54
- package/src/common/types.ts +3 -0
- package/src/gotenberg.ts +4 -4
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/interfaces/libre-office.types.ts +2 -2
- package/src/libre-office/utils/constants.ts +76 -76
- package/src/libre-office/utils/libre-office.utils.ts +42 -35
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +81 -69
- package/src/main.config.ts +22 -21
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +49 -49
- package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
- package/src/pdf-engines/utils/engine.utils.ts +20 -12
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
|
@@ -2,24 +2,24 @@ import FormData from "form-data";
|
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
3
|
|
|
4
4
|
export class GotenbergUtils {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
public static assert(condition: boolean, message: string): asserts condition {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new Error(message);
|
|
8
|
+
}
|
|
8
9
|
}
|
|
9
|
-
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
|
12
|
+
const response = await fetch(endpoint, {
|
|
13
|
+
method: "post",
|
|
14
|
+
body: data,
|
|
15
|
+
headers: {
|
|
16
|
+
...data.getHeaders(),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error(`${response.status} ${response.statusText}`);
|
|
22
|
+
}
|
|
23
|
+
return response.buffer();
|
|
22
24
|
}
|
|
23
|
-
return response.buffer();
|
|
24
|
-
}
|
|
25
25
|
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export {PdfFormat} from "./constants";
|
|
2
|
+
export {GotenbergUtils} from "./gotenberg.utils";
|
|
3
|
+
export {PathLikeOrReadStream} from "./types"
|
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
import fetch from "node-fetch";
|
|
2
2
|
import FormData from "form-data";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {GotenbergUtils} from "./../gotenberg.utils";
|
|
5
5
|
|
|
6
|
-
const {
|
|
6
|
+
const {Response, FetchError} = jest.requireActual("node-fetch");
|
|
7
7
|
|
|
8
8
|
jest.mock("node-fetch", () => jest.fn());
|
|
9
9
|
|
|
10
10
|
describe("GotenbergUtils", () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("assert", () => {
|
|
16
|
-
const errorMessage = "error message";
|
|
17
|
-
describe("when condition is true", () => {
|
|
18
|
-
it("should pass", () => {
|
|
19
|
-
expect(() => GotenbergUtils.assert(true, errorMessage)).not.toThrow();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe("when condition is false", () => {
|
|
23
|
-
it("should return error message", () => {
|
|
24
|
-
expect(() => GotenbergUtils.assert(false, errorMessage)).toThrow(
|
|
25
|
-
errorMessage
|
|
26
|
-
);
|
|
27
|
-
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
jest.resetAllMocks();
|
|
28
13
|
});
|
|
29
|
-
});
|
|
30
14
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
describe("assert", () => {
|
|
16
|
+
const errorMessage = "error message";
|
|
17
|
+
describe("when condition is true", () => {
|
|
18
|
+
it("should pass", () => {
|
|
19
|
+
expect(() => GotenbergUtils.assert(true, errorMessage)).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("when condition is false", () => {
|
|
23
|
+
it("should return error message", () => {
|
|
24
|
+
expect(() => GotenbergUtils.assert(false, errorMessage)).toThrow(
|
|
25
|
+
errorMessage
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
42
29
|
});
|
|
43
30
|
|
|
44
|
-
describe("
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
describe("fetch", () => {
|
|
32
|
+
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
33
|
+
const data = new FormData();
|
|
34
|
+
const endpoint = "http://localhost:3000/forms/chromium/convert/html";
|
|
35
|
+
|
|
36
|
+
describe("when fetch request succeeds", () => {
|
|
37
|
+
it("should return a buffer", async () => {
|
|
38
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
39
|
+
const response = await GotenbergUtils.fetch(endpoint, data);
|
|
40
|
+
await expect(response).toEqual(Buffer.from("content"));
|
|
41
|
+
});
|
|
53
42
|
});
|
|
54
|
-
});
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
describe("when fetch request fails", () => {
|
|
45
|
+
describe("when there is a known error", () => {
|
|
46
|
+
it("should throw an error", async () => {
|
|
47
|
+
const errorMessage =
|
|
48
|
+
"FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
|
|
49
|
+
mockFetch.mockRejectedValueOnce(new FetchError(errorMessage));
|
|
50
|
+
await expect(() =>
|
|
51
|
+
GotenbergUtils.fetch(endpoint, data)
|
|
52
|
+
).rejects.toThrow(errorMessage);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("when there is an unknown error", () => {
|
|
57
|
+
it("should throw an error", async () => {
|
|
58
|
+
mockFetch.mockResolvedValueOnce(
|
|
59
|
+
new Response(
|
|
60
|
+
{},
|
|
61
|
+
{status: 500, statusText: "Internal server error"}
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
await expect(() =>
|
|
65
|
+
GotenbergUtils.fetch(endpoint, data)
|
|
66
|
+
).rejects.toThrow("500 Internal server error");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
67
69
|
});
|
|
68
|
-
});
|
|
69
70
|
});
|
|
70
|
-
});
|
|
71
71
|
});
|
package/src/gotenberg.ts
CHANGED
|
@@ -8,14 +8,14 @@ import config from "config";
|
|
|
8
8
|
const envFile = `.env.${process.env.NODE_ENV}`;
|
|
9
9
|
const envFileFallback = ".env";
|
|
10
10
|
|
|
11
|
-
const dotenvConfig = dotenv.config({
|
|
11
|
+
const dotenvConfig = dotenv.config({path: path.resolve(envFile)});
|
|
12
12
|
|
|
13
13
|
// Fallback to loading the default environment file.
|
|
14
14
|
if (dotenvConfig.error) {
|
|
15
|
-
|
|
15
|
+
dotenv.config({path: path.resolve(envFileFallback)});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class Gotenberg {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
public static endpoint: string =
|
|
20
|
+
process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
|
|
21
21
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export {PageProperties} from "./interfaces/libre-office.types";
|
|
2
|
+
export {LibreOfficeUtils} from "./utils/libre-office.utils";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type PageProperties = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
landscape?: boolean; // Set the paper orientation to landscape (default false)
|
|
3
|
+
nativePageRanges?: { from: number; to: number }; // Page ranges to print
|
|
4
4
|
};
|
|
@@ -1,78 +1,78 @@
|
|
|
1
1
|
export const LIBRE_OFFICE_EXTENSIONS = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
2
|
+
".bib",
|
|
3
|
+
".doc",
|
|
4
|
+
".xml",
|
|
5
|
+
".docx",
|
|
6
|
+
".fodt",
|
|
7
|
+
".html",
|
|
8
|
+
".ltx",
|
|
9
|
+
".txt",
|
|
10
|
+
".odt",
|
|
11
|
+
".ott",
|
|
12
|
+
".pdb",
|
|
13
|
+
".pdf",
|
|
14
|
+
".psw",
|
|
15
|
+
".rtf",
|
|
16
|
+
".sdw",
|
|
17
|
+
".stw",
|
|
18
|
+
".sxw",
|
|
19
|
+
".uot",
|
|
20
|
+
".vor",
|
|
21
|
+
".wps",
|
|
22
|
+
".epub",
|
|
23
|
+
".png",
|
|
24
|
+
".bmp",
|
|
25
|
+
".emf",
|
|
26
|
+
".eps",
|
|
27
|
+
".fodg",
|
|
28
|
+
".gif",
|
|
29
|
+
".jpg",
|
|
30
|
+
".met",
|
|
31
|
+
".odd",
|
|
32
|
+
".otg",
|
|
33
|
+
".pbm",
|
|
34
|
+
".pct",
|
|
35
|
+
".pgm",
|
|
36
|
+
".ppm",
|
|
37
|
+
".ras",
|
|
38
|
+
".std",
|
|
39
|
+
".svg",
|
|
40
|
+
".svm",
|
|
41
|
+
".swf",
|
|
42
|
+
".sxd",
|
|
43
|
+
".sxw",
|
|
44
|
+
".tiff",
|
|
45
|
+
".xhtml",
|
|
46
|
+
".xpm",
|
|
47
|
+
".fodp",
|
|
48
|
+
".potm",
|
|
49
|
+
".pot",
|
|
50
|
+
".pptx",
|
|
51
|
+
".pps",
|
|
52
|
+
".ppt",
|
|
53
|
+
".pwp",
|
|
54
|
+
".sda",
|
|
55
|
+
".sdd",
|
|
56
|
+
".sti",
|
|
57
|
+
".sxi",
|
|
58
|
+
".uop",
|
|
59
|
+
".wmf",
|
|
60
|
+
".csv",
|
|
61
|
+
".dbf",
|
|
62
|
+
".dif",
|
|
63
|
+
".fods",
|
|
64
|
+
".ods",
|
|
65
|
+
".ots",
|
|
66
|
+
".pxl",
|
|
67
|
+
".sdc",
|
|
68
|
+
".slk",
|
|
69
|
+
".stc",
|
|
70
|
+
".sxc",
|
|
71
|
+
".uos",
|
|
72
|
+
".xls",
|
|
73
|
+
".xlt",
|
|
74
|
+
".xlsx",
|
|
75
|
+
".tif",
|
|
76
|
+
".jpeg",
|
|
77
|
+
".odp",
|
|
78
78
|
];
|
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {constants, createReadStream, promises, ReadStream} from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
4
|
import FormData from "form-data";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
|
|
7
|
+
import {LIBRE_OFFICE_EXTENSIONS} from "./constants";
|
|
8
|
+
import {PageProperties} from "../interfaces/libre-office.types";
|
|
9
9
|
|
|
10
10
|
export class LibreOfficeUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
public static async addFiles(files: PathLikeOrReadStream[], data: FormData) {
|
|
12
|
+
for (const [key, file] of files.entries()) {
|
|
13
|
+
const filename = `file${key}`
|
|
14
|
+
if (Buffer.isBuffer(file)) {
|
|
15
|
+
data.append("files", file, filename);
|
|
16
|
+
} else if (file instanceof ReadStream) {
|
|
17
|
+
data.append("files", file, filename);
|
|
18
|
+
} else {
|
|
19
|
+
await promises.access(file, constants.R_OK);
|
|
20
|
+
const filename = path.basename(file.toString());
|
|
21
|
+
const extension = path.extname(filename);
|
|
22
|
+
if (LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
|
|
23
|
+
data.append("files", createReadStream(file), filename);
|
|
24
|
+
} else {
|
|
25
|
+
throw new Error(`${extension} is not supported`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
|
-
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
public static addPageProperties(
|
|
32
|
+
data: FormData,
|
|
33
|
+
pageProperties: PageProperties
|
|
34
|
+
): void {
|
|
35
|
+
if (pageProperties.landscape) {
|
|
36
|
+
data.append("landscape", String(pageProperties.landscape));
|
|
37
|
+
}
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
if (pageProperties.nativePageRanges) {
|
|
40
|
+
GotenbergUtils.assert(
|
|
41
|
+
pageProperties.nativePageRanges.from > 0 &&
|
|
42
|
+
pageProperties.nativePageRanges.to > 0 &&
|
|
43
|
+
pageProperties.nativePageRanges.to >=
|
|
44
|
+
pageProperties.nativePageRanges.from,
|
|
45
|
+
"page ranges syntax error"
|
|
46
|
+
);
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
data.append(
|
|
49
|
+
"nativePageRanges",
|
|
50
|
+
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
|
-
}
|
|
47
54
|
}
|
|
@@ -1,86 +1,98 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {promises, createReadStream} from "fs";
|
|
3
|
+
import {LibreOfficeUtils} from "../libre-office.utils";
|
|
4
4
|
|
|
5
5
|
import FormData from "form-data";
|
|
6
6
|
|
|
7
7
|
describe("LibreOfficeUtils", () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
9
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
10
|
+
const data = new FormData();
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.resetAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("injectFiles", () => {
|
|
23
|
-
describe("when files exist", () => {
|
|
24
|
-
it("should append each file to data", async () => {
|
|
25
|
-
mockPromisesAccess.mockResolvedValue();
|
|
26
|
-
await LibreOfficeUtils.injectFiles(
|
|
27
|
-
["path/to/file.docx", "path/to/file.bib"],
|
|
28
|
-
data
|
|
29
|
-
);
|
|
30
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
31
|
-
});
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
(createReadStream as jest.Mock) = jest
|
|
14
|
+
.fn()
|
|
15
|
+
.mockImplementation((file) => file);
|
|
32
16
|
});
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
mockPromisesAccess.mockResolvedValue();
|
|
37
|
-
await expect(() =>
|
|
38
|
-
LibreOfficeUtils.injectFiles(
|
|
39
|
-
["path/to/file.rar", "path/to/file.pdf"],
|
|
40
|
-
data
|
|
41
|
-
)
|
|
42
|
-
).rejects.toThrow(".rar is not supported");
|
|
43
|
-
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
jest.resetAllMocks();
|
|
44
20
|
});
|
|
45
21
|
|
|
46
|
-
describe("
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
22
|
+
describe("addFiles", () => {
|
|
23
|
+
describe("when files exist", () => {
|
|
24
|
+
describe("when files parameter contains paths", () => {
|
|
25
|
+
it("should append each file to data", async () => {
|
|
26
|
+
mockPromisesAccess.mockResolvedValue();
|
|
27
|
+
await LibreOfficeUtils.addFiles(
|
|
28
|
+
["path/to/file.docx", "path/to/file.bib"],
|
|
29
|
+
data
|
|
30
|
+
);
|
|
31
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
32
|
+
});
|
|
33
|
+
})
|
|
34
|
+
describe("when files parameter contains a buffer", () => {
|
|
35
|
+
it("should append each file to data", async () => {
|
|
36
|
+
mockPromisesAccess.mockResolvedValue();
|
|
37
|
+
await LibreOfficeUtils.addFiles(
|
|
38
|
+
[Buffer.from("data"), "path/to/file.bib"],
|
|
39
|
+
data
|
|
40
|
+
);
|
|
41
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
});
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
46
|
+
describe("when one of the files has unsupported format", () => {
|
|
47
|
+
it("should throw an error", async () => {
|
|
48
|
+
mockPromisesAccess.mockResolvedValue();
|
|
49
|
+
await expect(() =>
|
|
50
|
+
LibreOfficeUtils.addFiles(
|
|
51
|
+
["path/to/file.rar", "path/to/file.pdf"],
|
|
52
|
+
data
|
|
53
|
+
)
|
|
54
|
+
).rejects.toThrow(".rar is not supported");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("when one of the files does not exist", () => {
|
|
59
|
+
it("should throw an error", async () => {
|
|
60
|
+
const errorMessage =
|
|
61
|
+
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
62
|
+
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
63
|
+
await expect(() =>
|
|
64
|
+
LibreOfficeUtils.addFiles(
|
|
65
|
+
["path/to/file.pdf", "path/to/another-file.pdf"],
|
|
66
|
+
data
|
|
67
|
+
)
|
|
68
|
+
).rejects.toThrow(errorMessage);
|
|
69
|
+
});
|
|
70
70
|
});
|
|
71
|
-
});
|
|
72
71
|
});
|
|
73
72
|
|
|
74
|
-
describe("
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
describe("addPageProperties", () => {
|
|
74
|
+
describe("Page landscape", () => {
|
|
75
|
+
describe("when landscape parameter is set", () => {
|
|
76
|
+
it("should append landscape to data", () => {
|
|
77
|
+
LibreOfficeUtils.addPageProperties(data, {
|
|
78
|
+
landscape: true,
|
|
79
|
+
});
|
|
80
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
|
|
81
|
+
expect(data.append).toHaveBeenCalledWith("landscape", "true");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("Page ranges", () => {
|
|
87
|
+
describe("when nativePageRanges is valid", () => {
|
|
88
|
+
it("should append nativePageRanges to data", () => {
|
|
89
|
+
LibreOfficeUtils.addPageProperties(data, {
|
|
90
|
+
nativePageRanges: {from: 1, to: 6},
|
|
91
|
+
});
|
|
92
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
82
96
|
});
|
|
83
|
-
});
|
|
84
97
|
});
|
|
85
|
-
});
|
|
86
98
|
});
|