mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 12:42:44 +01:00
added /external unit tests [cdn]
This commit is contained in:
parent
976512a0ac
commit
6ceb710df9
@ -3,6 +3,9 @@ const path = require("path");
|
|||||||
const fse = require("fs-extra");
|
const fse = require("fs-extra");
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
// TODO: write unittest to check if FileStorage.ts is working
|
||||||
|
// TODO: write unitest to check if env vars are defined
|
||||||
|
|
||||||
if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
|
if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
|
||||||
// TODO:nodejs path.join trailing slash windows compatible
|
// TODO:nodejs path.join trailing slash windows compatible
|
||||||
if (process.env.STORAGE_PROVIDER === "file") {
|
if (process.env.STORAGE_PROVIDER === "file") {
|
||||||
@ -15,7 +18,6 @@ if (process.env.STORAGE_PROVIDER === "file") {
|
|||||||
}
|
}
|
||||||
fse.ensureDirSync(process.env.STORAGE_LOCATION);
|
fse.ensureDirSync(process.env.STORAGE_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { CDNServer } = require("../dist/Server");
|
const { CDNServer } = require("../dist/Server");
|
||||||
const { Config } = require("@fosscord/util");
|
const { Config } = require("@fosscord/util");
|
||||||
const supertest = require("supertest");
|
const supertest = require("supertest");
|
||||||
@ -153,3 +155,57 @@ describe("/avatars", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("/external", () => {
|
||||||
|
describe("POST", () => {
|
||||||
|
describe("without signature specified", () => {
|
||||||
|
test("route should respond with 400", async () => {
|
||||||
|
const response = await request.post("/external");
|
||||||
|
expect(response.statusCode).toBe(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("with signature specified, without file specified", () => {
|
||||||
|
test("route should respond with 400", async () => {
|
||||||
|
const response = await request
|
||||||
|
.post("/external")
|
||||||
|
.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("/external")
|
||||||
|
.set({ signature: Config.get().security.requestSignature })
|
||||||
|
.send({ url: "https://i.ytimg.com/vi_webp/TiXzhQr5AUc/mqdefault.webp" });
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
expect(response.headers["content-type"]).toEqual(expect.stringContaining("json"));
|
||||||
|
expect(response.body.id).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("with signature specified, with falsy url specified ", () => {
|
||||||
|
test("route should respond with 400", async () => {
|
||||||
|
const response = await request
|
||||||
|
.post("/external")
|
||||||
|
.set({ signature: Config.get().security.requestSignature })
|
||||||
|
.send({
|
||||||
|
url: "notavalidurl.123",
|
||||||
|
});
|
||||||
|
expect(response.statusCode).toBe(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("GET", () => {
|
||||||
|
describe("getting uploaded image by url returned by POST /avatars", () => {
|
||||||
|
test("route should respond with 200", async () => {
|
||||||
|
let response = await request
|
||||||
|
.post("/external")
|
||||||
|
.set({ signature: Config.get().security.requestSignature })
|
||||||
|
.send({ url: "https://i.ytimg.com/vi_webp/TiXzhQr5AUc/mqdefault.webp" });
|
||||||
|
request.get(`external/${response.body.id}`).then((x) => {
|
||||||
|
expect(x.statusCode).toBe(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user