-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
54 lines (40 loc) · 1.38 KB
/
test.ts
1
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
import {
executor,
handleResponse,
handleZipResponse,
office,
readFile,
url,
} from "./mod.ts";
import { assert } from "https://deno.land/std@0.121.0/testing/asserts.ts";
const __API_URL__ = "https://demo.gotenberg.dev/";
Deno.test("Test that api is running", async () => {
const res = await fetch(new URL("/prometheus/metrics", __API_URL__));
assert(res.status === 200, "API returns status code " + res.status);
const t = await res.text();
assert(t.length > 100, "Falsy response");
});
async function isPDF(file: Blob) {
const arrayBuffer = await file.arrayBuffer();
const start = String.fromCharCode(...new Uint8Array(arrayBuffer.slice(0, 4)));
assert(start === "%PDF", "Returned file is no pdf!");
}
Deno.test("API with returned PDF works", async () => {
const gotenberg = executor(__API_URL__);
const res = await handleResponse(
gotenberg(url("https://www.google.de/")),
);
await isPDF(res.content);
});
Deno.test("API with returned ZIP works", async () => {
const gotenberg = executor(__API_URL__);
const files = [
await readFile("./example.docx", "file1.docx"),
await readFile("./example.docx", "file2.docx"),
];
const res = await handleZipResponse(gotenberg(office(files)));
for (let i = 0; i < res.length; i++) {
assert(res[i].filename.endsWith(".pdf"), "Filenames doesn't end with pdf!");
await isPDF(res[i].content);
}
});