Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production deploy #2431

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions api.planx.uk/modules/file/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,10 @@ describe("File upload", () => {

describe("Private", () => {
const ENDPOINT = "/file/private/upload";
const auth = authHeader({ role: "teamEditor" });

it("returns an error if authorization headers are not set", async () => {
await supertest(app)
.post("/flows/1/move/new-team")
.expect(401)
.then((res) => {
expect(res.body).toEqual({
error: "No authorization token was found",
});
});
});

it("should not upload without filename", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "")
.attach("file", Buffer.from("some data"), "some_file.txt")
.expect(400)
Expand All @@ -73,7 +60,6 @@ describe("File upload", () => {
it("should not upload without file", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "some filename")
.expect(500)
.then((res) => {
Expand All @@ -85,7 +71,6 @@ describe("File upload", () => {
it("should upload file", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "some_file.txt")
.attach("file", Buffer.from("some data"), "some_file.txt")
.then((res) => {
Expand All @@ -107,7 +92,6 @@ describe("File upload", () => {

await supertest(app)
.post("/file/private/upload")
.set(auth)
.field("filename", "some_file.txt")
.attach("file", Buffer.from("some data"), "some_file.txt")
.expect(500)
Expand All @@ -121,9 +105,23 @@ describe("File upload", () => {
describe("Public", () => {
const ENDPOINT = "/file/public/upload";

const auth = authHeader({ role: "teamEditor" });

it("returns an error if authorization headers are not set", async () => {
await supertest(app)
.post("/flows/1/move/new-team")
.expect(401)
.then((res) => {
expect(res.body).toEqual({
error: "No authorization token was found",
});
});
});

it("should not upload without filename", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "")
.attach("file", Buffer.from("some data"), "some_file.txt")
.expect(400)
Expand All @@ -137,6 +135,7 @@ describe("File upload", () => {
it("should not upload without file", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "some filename")
.expect(500)
.then((res) => {
Expand All @@ -148,6 +147,7 @@ describe("File upload", () => {
it("should upload file", async () => {
await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "some_file.txt")
.attach("file", Buffer.from("some data"), "some_file.txt")
.then((res) => {
Expand All @@ -169,6 +169,7 @@ describe("File upload", () => {

await supertest(app)
.post(ENDPOINT)
.set(auth)
.field("filename", "some_file.txt")
.attach("file", Buffer.from("some data"), "some_file.txt")
.expect(500)
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const router = Router();
router.post(
"/public/upload",
multer().single("file"),
useTeamEditorAuth,
validate(uploadFileSchema),
publicUploadController,
);

router.post(
"/private/upload",
multer().single("file"),
useTeamEditorAuth,
validate(uploadFileSchema),
privateUploadController,
);
Expand Down
1 change: 0 additions & 1 deletion api.planx.uk/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ app.use("/webhooks", webhookRoutes);
app.use("/analytics", analyticsRoutes);
app.use("/admin", adminRoutes);
app.use(ordnanceSurveyRoutes);
app.use(fileRoutes);
app.use("/file", fileRoutes);

app.use("/gis", router);
Expand Down
Loading