-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.ts
48 lines (40 loc) · 1.59 KB
/
tests.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
import { assertEquals } from "https://deno.land/std@0.218.0/assert/mod.ts";
import axiod from "https://deno.land/x/axiod@0.26.0/mod.ts";
import config from "./utils/config.ts";
const port = config["serverPort"];
Deno.test("Upload Test", async () => {
const formData = new FormData();
formData.append("file", new File(["Hello, World!"], "test.txt"));
const uploadResponse = await axiod.post(
`http://localhost:${port}/upload`,
formData
);
const result = await uploadResponse.data;
assertEquals(result["message"], "File uploaded successfully");
assertEquals(uploadResponse.status, 200);
console.log("Upload Response: ", result);
const fetchResponse = await axiod.get(
`http://localhost:${port}/fetch?fileId=${result["fileId"]}`
);
assertEquals(fetchResponse.data, "Hello, World!");
assertEquals(fetchResponse.status, 200);
console.log(fetchResponse.data);
});
Deno.test("Fetch Non-Existent File Test", async () => {
await axiod
.get(`http://localhost:${port}/fetch?fileId=blablabla&mainFileName=x.txt`)
.catch((e) => {
assertEquals(e.response.data["message"], "Failed to download the file");
assertEquals(e.response.status, 400);
console.log(e.response.data);
});
});
Deno.test("Upload Empty File Test", async () => {
const formData = new FormData();
formData.append("file", new File([""], "test.txt"));
await axiod.post(`http://localhost:${port}/upload`, formData).catch((e) => {
assertEquals(e.response.data["message"], "File size is too large or empty");
assertEquals(e.response.status, 400);
console.log(e.response.data);
});
});