summary refs log tree commit diff
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
commit4adf2bdc54645f185c87d25cc355fb38ab8cfdf0 (patch)
treeef5d7a3f565981c5dc15575f11d97ae261d0b2b5
parentfixed tests for cdn (diff)
downloadserver-4adf2bdc54645f185c87d25cc355fb38ab8cfdf0.tar.xz
added /avatars unittests [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();
+				});
+			});
+		});
+	});
+});