chromiumly 2.4.0 → 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.
Files changed (66) hide show
  1. package/dist/chromium/converters/converter.js.map +1 -1
  2. package/dist/chromium/converters/html.converter.d.ts +4 -6
  3. package/dist/chromium/converters/html.converter.js +3 -9
  4. package/dist/chromium/converters/html.converter.js.map +1 -1
  5. package/dist/chromium/converters/markdown.converter.d.ts +5 -7
  6. package/dist/chromium/converters/markdown.converter.js +3 -16
  7. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  8. package/dist/chromium/converters/url.converter.d.ts +3 -5
  9. package/dist/chromium/converters/url.converter.js +1 -1
  10. package/dist/chromium/converters/url.converter.js.map +1 -1
  11. package/dist/chromium/index.js.map +1 -1
  12. package/dist/chromium/interfaces/converter.types.d.ts +3 -6
  13. package/dist/chromium/utils/converter.utils.d.ts +3 -1
  14. package/dist/chromium/utils/converter.utils.js +24 -21
  15. package/dist/chromium/utils/converter.utils.js.map +1 -1
  16. package/dist/common/constants.js.map +1 -1
  17. package/dist/common/gotenberg.utils.js.map +1 -1
  18. package/dist/common/index.d.ts +1 -0
  19. package/dist/common/index.js.map +1 -1
  20. package/dist/common/types.d.ts +3 -0
  21. package/dist/common/types.js +3 -0
  22. package/dist/common/types.js.map +1 -0
  23. package/dist/gotenberg.js.map +1 -1
  24. package/dist/libre-office/index.js.map +1 -1
  25. package/dist/libre-office/utils/constants.js.map +1 -1
  26. package/dist/libre-office/utils/libre-office.utils.d.ts +3 -4
  27. package/dist/libre-office/utils/libre-office.utils.js +18 -9
  28. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  29. package/dist/main.config.js.map +1 -1
  30. package/dist/main.js.map +1 -1
  31. package/dist/pdf-engines/index.js.map +1 -1
  32. package/dist/pdf-engines/pdf.engine.js +3 -3
  33. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  34. package/dist/pdf-engines/utils/engine.utils.d.ts +2 -3
  35. package/dist/pdf-engines/utils/engine.utils.js +17 -8
  36. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/chromium/converters/converter.ts +5 -5
  39. package/src/chromium/converters/html.converter.ts +54 -60
  40. package/src/chromium/converters/markdown.converter.ts +56 -68
  41. package/src/chromium/converters/tests/html.converter.test.ts +119 -135
  42. package/src/chromium/converters/tests/markdown.converter.test.ts +131 -150
  43. package/src/chromium/converters/tests/url.converter.test.ts +114 -123
  44. package/src/chromium/converters/url.converter.ts +55 -57
  45. package/src/chromium/index.ts +3 -3
  46. package/src/chromium/interfaces/converter.types.ts +27 -27
  47. package/src/chromium/utils/converter.utils.ts +141 -139
  48. package/src/chromium/utils/tests/converter.utils.test.ts +312 -311
  49. package/src/common/constants.ts +3 -3
  50. package/src/common/gotenberg.utils.ts +16 -16
  51. package/src/common/index.ts +3 -2
  52. package/src/common/tests/gotenberg.utils.test.ts +54 -54
  53. package/src/common/types.ts +3 -0
  54. package/src/gotenberg.ts +4 -4
  55. package/src/libre-office/index.ts +2 -2
  56. package/src/libre-office/interfaces/libre-office.types.ts +2 -2
  57. package/src/libre-office/utils/constants.ts +76 -76
  58. package/src/libre-office/utils/libre-office.utils.ts +42 -35
  59. package/src/libre-office/utils/tests/libre-office.utils.test.ts +81 -69
  60. package/src/main.config.ts +22 -21
  61. package/src/main.ts +3 -3
  62. package/src/pdf-engines/index.ts +1 -1
  63. package/src/pdf-engines/pdf.engine.ts +49 -49
  64. package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
  65. package/src/pdf-engines/utils/engine.utils.ts +20 -12
  66. package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
@@ -1,5 +1,5 @@
1
1
  export enum PdfFormat {
2
- A_1a = "PDF/A-1a",
3
- A_2b = "PDF/A-2b",
4
- A_3b = "PDF/A-3b",
2
+ A_1a = "PDF/A-1a",
3
+ A_2b = "PDF/A-2b",
4
+ A_3b = "PDF/A-3b",
5
5
  }
@@ -2,24 +2,24 @@ import FormData from "form-data";
2
2
  import fetch from "node-fetch";
3
3
 
4
4
  export class GotenbergUtils {
5
- public static assert(condition: boolean, message: string): asserts condition {
6
- if (!condition) {
7
- throw new Error(message);
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
- 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
- });
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
- if (!response.ok) {
21
- throw new Error(`${response.status} ${response.statusText}`);
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
  }
@@ -1,2 +1,3 @@
1
- export { PdfFormat } from "./constants";
2
- export { GotenbergUtils } from "./gotenberg.utils";
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 { GotenbergUtils } from "./../gotenberg.utils";
4
+ import {GotenbergUtils} from "./../gotenberg.utils";
5
5
 
6
- const { Response, FetchError } = jest.requireActual("node-fetch");
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
- afterEach(() => {
12
- jest.resetAllMocks();
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
- 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
- });
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("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);
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
- 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");
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
  });
@@ -0,0 +1,3 @@
1
+ import {PathLike, ReadStream} from "fs";
2
+
3
+ export type PathLikeOrReadStream = PathLike | ReadStream
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({ path: path.resolve(envFile) });
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
- dotenv.config({ path: path.resolve(envFileFallback) });
15
+ dotenv.config({path: path.resolve(envFileFallback)});
16
16
  }
17
17
 
18
18
  export class Gotenberg {
19
- public static endpoint: string =
20
- process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
19
+ public static endpoint: string =
20
+ process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
21
21
  }
@@ -1,2 +1,2 @@
1
- export { PageProperties } from "./interfaces/libre-office.types";
2
- export { LibreOfficeUtils } from "./utils/libre-office.utils";
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
- landscape?: boolean; // Set the paper orientation to landscape (default false)
3
- nativePageRanges?: { from: number; to: number }; // Page ranges to print
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
- ".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",
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 { constants, createReadStream, PathLike, promises } from "fs";
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 { GotenbergUtils } from "../../common";
7
- import { LIBRE_OFFICE_EXTENSIONS } from "./constants";
8
- import { PageProperties } from "../interfaces/libre-office.types";
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
- public static async injectFiles(files: PathLike[], data: FormData) {
12
- for (const file of files) {
13
- await promises.access(file, constants.R_OK);
14
- const filename = path.basename(file.toString());
15
- const extension = path.extname(filename);
16
- if (LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
17
- data.append(filename, createReadStream(file));
18
- } else {
19
- throw new Error(`${extension} is not supported`);
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
- public static injectPageProperties(
25
- data: FormData,
26
- pageProperties: PageProperties
27
- ): void {
28
- if (pageProperties.landscape) {
29
- data.append("landscape", String(pageProperties.landscape));
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
- if (pageProperties.nativePageRanges) {
33
- GotenbergUtils.assert(
34
- pageProperties.nativePageRanges.from > 0 &&
35
- pageProperties.nativePageRanges.to > 0 &&
36
- pageProperties.nativePageRanges.to >=
37
- pageProperties.nativePageRanges.from,
38
- "page ranges syntax error"
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
- data.append(
42
- "nativePageRanges",
43
- `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
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 { promises, createReadStream } from "fs";
3
- import { LibreOfficeUtils } from "../libre-office.utils";
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
- const mockPromisesAccess = jest.spyOn(promises, "access");
9
- const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
10
- const data = new FormData();
8
+ const mockPromisesAccess = jest.spyOn(promises, "access");
9
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
10
+ const data = new FormData();
11
11
 
12
- beforeEach(() => {
13
- (createReadStream as jest.Mock) = jest
14
- .fn()
15
- .mockImplementation((file) => file);
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
- describe("when one of the files has unsupported format", () => {
35
- it("should throw an error", async () => {
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("when one of the files does not exist", () => {
47
- it("should throw an error", async () => {
48
- const errorMessage =
49
- "ENOENT: no such file or directory, access 'path/to/index.html'";
50
- mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
51
- await expect(() =>
52
- LibreOfficeUtils.injectFiles(
53
- ["path/to/file.pdf", "path/to/another-file.pdf"],
54
- data
55
- )
56
- ).rejects.toThrow(errorMessage);
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
- describe("injectPageProperties", () => {
62
- describe("Page landscape", () => {
63
- describe("when landscape parameter is set", () => {
64
- it("should append landscape to data", () => {
65
- LibreOfficeUtils.injectPageProperties(data, {
66
- landscape: true,
67
- });
68
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
69
- expect(data.append).toHaveBeenCalledWith("landscape", "true");
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("Page ranges", () => {
75
- describe("when nativePageRanges is valid", () => {
76
- it("should append nativePageRanges to data", () => {
77
- LibreOfficeUtils.injectPageProperties(data, {
78
- nativePageRanges: { from: 1, to: 6 },
79
- });
80
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
81
- expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
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
  });