summary refs log tree commit diff
path: root/cdn
diff options
context:
space:
mode:
authorxnacly <matteogropp@protonmail.com>2021-08-29 17:11:01 +0200
committerxnacly <matteogropp@protonmail.com>2021-08-29 17:11:01 +0200
commitdad0506df40f89c0b1fe9d2ae0d69fbe4035d29f (patch)
tree2e8789b95d1efb00eaf787873b716f0c968bf2e2 /cdn
parentfixed tests for cdn (diff)
downloadserver-dad0506df40f89c0b1fe9d2ae0d69fbe4035d29f.tar.xz
added /avatars unittests [cdn]
Diffstat (limited to 'cdn')
-rw-r--r--cdn/tests/server.test.js57
1 files changed, 56 insertions, 1 deletions
diff --git a/cdn/tests/server.test.js b/cdn/tests/server.test.js
index 13046034..6f06c2b6 100644
--- a/cdn/tests/server.test.js
+++ b/cdn/tests/server.test.js
@@ -67,7 +67,6 @@ describe("/attachments", () => {
 				expect(response.statusCode).toBe(200);
 				expect(response.headers["content-type"]).toEqual(expect.stringContaining("json"));
 				expect(response.body.url).toBeDefined();
-				attachment_url = response.body.url;
 			});
 		});
 	});
@@ -98,3 +97,59 @@ describe("/attachments", () => {
 		});
 	});
 });
+
+describe("/avatars", () => {
+	describe("POST", () => {
+		describe("without signature specified", () => {
+			test("route should respond with 400", async () => {
+				const response = await request.post("/avatars/123456789");
+				expect(response.statusCode).toBe(400);
+			});
+		});
+		describe("with signature specified, without file specified", () => {
+			test("route should respond with 400", async () => {
+				const response = await request
+					.post("/avatars/123456789")
+					.set({ signature: Config.get().security.requestSignature });
+				expect(response.statusCode).toBe(400);
+			});
+		});
+		describe("with signature specified, with file specified ", () => {
+			test("route should respond with Content-type: application/json, 200 and res.body.url", async () => {
+				const response = await request
+					.post("/avatars/123456789")
+					.set({ signature: Config.get().security.requestSignature })
+					.attach("file", __dirname + "/antman.jpg");
+				expect(response.statusCode).toBe(200);
+				expect(response.headers["content-type"]).toEqual(expect.stringContaining("json"));
+				expect(response.body.url).toBeDefined();
+			});
+		});
+	});
+	describe("GET", () => {
+		describe("getting uploaded image by url returned by POST /avatars", () => {
+			test("route should respond with 200", async () => {
+				let response = await request
+					.post("/avatars/123456789")
+					.set({ signature: Config.get().security.requestSignature })
+					.attach("file", __dirname + "/antman.jpg");
+				request.get(response.body.url.replace("http://localhost:3003", "")).then((x) => {
+					expect(x.statusCode).toBe(200);
+				});
+			});
+		});
+	});
+	describe("DELETE", () => {
+		describe("deleting uploaded image by url returned by POST /avatars", () => {
+			test("route should respond with res.body.success", async () => {
+				let response = await request
+					.post("/avatars/123456789")
+					.set({ signature: Config.get().security.requestSignature })
+					.attach("file", __dirname + "/antman.jpg");
+				request.delete(response.body.url.replace("http://localhost:3003", "")).then((x) => {
+					expect(x.body.success).toBeDefined();
+				});
+			});
+		});
+	});
+});