diff --git a/src/chromium/converters/tests/html.converter.test.ts b/src/chromium/converters/tests/html.converter.test.ts
index b4ff065c..53075ea5 100644
--- a/src/chromium/converters/tests/html.converter.test.ts
+++ b/src/chromium/converters/tests/html.converter.test.ts
@@ -1,4 +1,5 @@
-import { promises, createReadStream } from "fs";
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+import { createReadStream, promises } from "fs";
import fetch from "node-fetch";
import FormData from "form-data";
@@ -51,7 +52,7 @@ describe("HtmlConverter", () => {
html: "path/to/index.html",
pdfFormat: PdfFormat.A_1a,
});
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
expect(buffer).toEqual(Buffer.from("content"));
});
});
@@ -64,7 +65,49 @@ describe("HtmlConverter", () => {
html: "path/to/index.html",
properties: { size: { width: 8.3, height: 11.7 } },
});
- expect(mockFormDataAppend).toBeCalledTimes(3);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when header parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ header: "path/to/header.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when footer parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ footer: "path/to/footer.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when all parameters are passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ header: "path/to/header.html",
+ footer: "path/to/footer.html",
+ pdfFormat: PdfFormat.A_1a,
+ properties: { size: { width: 8.3, height: 11.7 } },
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(6);
expect(buffer).toEqual(Buffer.from("content"));
});
});
diff --git a/src/chromium/converters/tests/markdown.converter.test.ts b/src/chromium/converters/tests/markdown.converter.test.ts
index 1d343d70..0bdf10e3 100644
--- a/src/chromium/converters/tests/markdown.converter.test.ts
+++ b/src/chromium/converters/tests/markdown.converter.test.ts
@@ -1,5 +1,7 @@
-import FormData from "form-data";
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { createReadStream, promises } from "fs";
+
+import FormData from "form-data";
import fetch from "node-fetch";
import { PdfFormat } from "../../../common";
@@ -54,7 +56,7 @@ describe("MarkdownConverter", () => {
markdown: "path/to/file.md",
pdfFormat: PdfFormat.A_2b,
});
- expect(mockFormDataAppend).toBeCalledTimes(3);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
expect(buffer).toEqual(Buffer.from("content"));
});
});
@@ -68,7 +70,52 @@ describe("MarkdownConverter", () => {
markdown: "path/to/file.md",
properties: { size: { width: 8.3, height: 11.7 } },
});
- expect(mockFormDataAppend).toBeCalledTimes(4);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when header parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ markdown: "path/to/file.md",
+ header: "path/to/header.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when footer parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ markdown: "path/to/file.md",
+ footer: "path/to/footer.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when all parameters are passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ html: "path/to/index.html",
+ markdown: "path/to/file.md",
+ header: "path/to/header.html",
+ footer: "path/to/footer.html",
+ pdfFormat: PdfFormat.A_1a,
+ properties: { size: { width: 8.3, height: 11.7 } },
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
expect(buffer).toEqual(Buffer.from("content"));
});
});
diff --git a/src/chromium/converters/tests/url.converter.test.ts b/src/chromium/converters/tests/url.converter.test.ts
index d5c75f76..a21315ee 100644
--- a/src/chromium/converters/tests/url.converter.test.ts
+++ b/src/chromium/converters/tests/url.converter.test.ts
@@ -1,3 +1,5 @@
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+import { createReadStream, promises } from "fs";
import FormData from "form-data";
import fetch from "node-fetch";
@@ -10,9 +12,16 @@ jest.mock("node-fetch", () => jest.fn());
describe("HtmlConverter", () => {
const mockFetch = fetch as jest.MockedFunction;
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
+ const mockPromisesAccess = jest.spyOn(promises, "access");
const converter = new UrlConverter();
+ beforeEach(() => {
+ (createReadStream as jest.Mock) = jest
+ .fn()
+ .mockImplementation((file) => file);
+ });
+
afterEach(() => {
jest.resetAllMocks();
});
@@ -36,6 +45,34 @@ describe("HtmlConverter", () => {
});
});
+ describe("when header parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockFetch.mockResolvedValueOnce(new Response("content"));
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ url: "http://www.example.com/",
+ header: "path/to/header.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when footer parameter is passed", () => {
+ it("should return a buffer", async () => {
+ mockFetch.mockResolvedValueOnce(new Response("content"));
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ url: "http://www.example.com/",
+ footer: "path/to/footer.html",
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
describe("when pdf format parameter is passed", () => {
it("should return a buffer", async () => {
mockFetch.mockResolvedValueOnce(new Response("content"));
@@ -43,7 +80,7 @@ describe("HtmlConverter", () => {
url: "http://www.example.com/",
pdfFormat: PdfFormat.A_3b,
});
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
expect(buffer).toEqual(Buffer.from("content"));
});
});
@@ -55,7 +92,23 @@ describe("HtmlConverter", () => {
url: "http://www.example.com/",
properties: { size: { width: 8.3, height: 11.7 } },
});
- expect(mockFormDataAppend).toBeCalledTimes(3);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
+ expect(buffer).toEqual(Buffer.from("content"));
+ });
+ });
+
+ describe("when all parameters are passed", () => {
+ it("should return a buffer", async () => {
+ mockPromisesAccess.mockResolvedValue();
+ mockFetch.mockResolvedValue(new Response("content"));
+ const buffer = await converter.convert({
+ url: "http://www.example.com/",
+ header: "path/to/header.html",
+ footer: "path/to/footer.html",
+ pdfFormat: PdfFormat.A_1a,
+ properties: { size: { width: 8.3, height: 11.7 } },
+ });
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(6);
expect(buffer).toEqual(Buffer.from("content"));
});
});
diff --git a/src/libre-office/utils/tests/libre-office.utils.test.ts b/src/libre-office/utils/tests/libre-office.utils.test.ts
index 835c98d7..dff96f9c 100644
--- a/src/libre-office/utils/tests/libre-office.utils.test.ts
+++ b/src/libre-office/utils/tests/libre-office.utils.test.ts
@@ -1,5 +1,6 @@
-import { LibreOfficeUtils } from "../libre-office.utils";
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { promises, createReadStream } from "fs";
+import { LibreOfficeUtils } from "../libre-office.utils";
import FormData from "form-data";
@@ -26,7 +27,7 @@ describe("LibreOfficeUtils", () => {
["path/to/file.docx", "path/to/file.bib"],
data
);
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
});
});
@@ -64,7 +65,7 @@ describe("LibreOfficeUtils", () => {
LibreOfficeUtils.injectPageProperties(data, {
landscape: true,
});
- expect(mockFormDataAppend).toBeCalledTimes(1);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
expect(data.append).toHaveBeenCalledWith("landscape", "true");
});
});
@@ -76,7 +77,7 @@ describe("LibreOfficeUtils", () => {
LibreOfficeUtils.injectPageProperties(data, {
nativePageRanges: { from: 1, to: 6 },
});
- expect(mockFormDataAppend).toBeCalledTimes(1);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
});
});
diff --git a/src/pdf-engines/tests/pdf.engine.test.ts b/src/pdf-engines/tests/pdf.engine.test.ts
index 854c299c..a94a362f 100644
--- a/src/pdf-engines/tests/pdf.engine.test.ts
+++ b/src/pdf-engines/tests/pdf.engine.test.ts
@@ -1,5 +1,6 @@
-import FormData from "form-data";
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { createReadStream, promises } from "fs";
+import FormData from "form-data";
import fs from "fs/promises";
import fetch from "node-fetch";
import path from "path";
@@ -34,7 +35,7 @@ describe("PDFEngine", () => {
files: ["path/to/file.docx", "path/to/file.bib"],
});
expect(buffer).toEqual(Buffer.from("content"));
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
});
});
@@ -49,7 +50,7 @@ describe("PDFEngine", () => {
merge: true,
});
expect(buffer).toEqual(Buffer.from("content"));
- expect(mockFormDataAppend).toBeCalledTimes(5);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(5);
});
});
});
@@ -62,7 +63,7 @@ describe("PDFEngine", () => {
files: ["path/to/file.pdf", "path/to/another-file.pdf"],
});
expect(buffer).toEqual(Buffer.from("content"));
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
});
});
diff --git a/src/pdf-engines/utils/tests/engine.utils.test.ts b/src/pdf-engines/utils/tests/engine.utils.test.ts
index 112a2700..0d034641 100644
--- a/src/pdf-engines/utils/tests/engine.utils.test.ts
+++ b/src/pdf-engines/utils/tests/engine.utils.test.ts
@@ -1,8 +1,9 @@
-import { PDFEngineUtils } from "./../engine.utils";
-import { promises, createReadStream } from "fs";
-
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+import { createReadStream, promises } from "fs";
import FormData from "form-data";
+import { PDFEngineUtils } from "./../engine.utils";
+
describe("PDFEngineUtils", () => {
const mockPromisesAccess = jest.spyOn(promises, "access");
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
@@ -26,7 +27,7 @@ describe("PDFEngineUtils", () => {
["path/to/file.pdf", "path/to/another-file.pdf"],
data
);
- expect(mockFormDataAppend).toBeCalledTimes(2);
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
});
});