Added: tests for reviews, Reviews GET API endpoint; Fixed: tests for beers

This commit is contained in:
Filip Rojek 2024-05-12 22:15:54 +02:00
parent 2168756afd
commit 312809f34f
3 changed files with 106 additions and 25 deletions

View File

@ -10,6 +10,7 @@ import validate from "../middlewares/validateRequest";
import valMulter from "../middlewares/validateMulterRequest"; import valMulter from "../middlewares/validateMulterRequest";
import * as AuthVal from "../validators/authValidator"; import * as AuthVal from "../validators/authValidator";
import * as BVal from "../validators/beerValidator"; import * as BVal from "../validators/beerValidator";
import * as RVal from "../validators/reviewValidator";
const upload = multer({ dest: path.resolve(__dirname, "../../uploads") }); const upload = multer({ dest: path.resolve(__dirname, "../../uploads") });
@ -35,6 +36,7 @@ router.post(
beerController.edit_post, beerController.edit_post,
); );
router.post("/review/add", requireAuth, reviewController.add_post); router.post("/review/add", [requireAuth, validate(RVal.add)], reviewController.add_post);
router.get("/review/get", requireAuth, reviewController.get_get);
export default router; export default router;

View File

@ -19,6 +19,33 @@ describe("POST /api/v1/beer/add", () => {
expect(res.statusCode).toBe(400); expect(res.statusCode).toBe(400);
}); });
test("should drop 400 (name)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.name;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (degree)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.degree;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (packaging)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.packaging;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (brand)", async () => { test("should drop 400 (brand)", async () => {
const jwt = await login(); const jwt = await login();
const body: any = { ...addExam }; const body: any = { ...addExam };

View File

@ -1,7 +1,7 @@
import supertest from "supertest"; import supertest from "supertest";
import { app } from "../src/app"; import { app } from "../src/app";
import { login } from "./auth.test"; import { login } from "./auth.test";
//import { addExam, delExam, editExam } from '../src/validators/beerValidator'; import { addExam, delExam } from "../src/validators/reviewValidator";
const request = supertest(app); const request = supertest(app);
@ -16,32 +16,84 @@ describe("POST /api/v1/review/add", () => {
const jwt = await login(); const jwt = await login();
const res = await request.post(url).set("Cookie", jwt).send({}); const res = await request.post(url).set("Cookie", jwt).send({});
console.log("TEST", await res.body); expect(res.statusCode).toBe(400);
});
test("should drop 400 (foam)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.foam;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400); expect(res.statusCode).toBe(400);
}); });
// test('should drop 201', async () => { test("should drop 400 (bitter_sweetness)", async () => {
// const jwt = await login(); const jwt = await login();
// const res = await request.post(url).set('Cookie', jwt).send(addExam); const body: any = { ...addExam };
// delete body.bitter_sweetness;
// expect(res.statusCode).toBe(201); const res = await request.post(url).set("Cookie", jwt).send(body);
// });
expect(res.statusCode).toBe(400);
});
test("should drop 400 (taste)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.taste;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (packaging)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.packaging;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (sourness)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.sourness;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 400 (would_again)", async () => {
const jwt = await login();
const body: any = { ...addExam };
delete body.would_again;
const res = await request.post(url).set("Cookie", jwt).send(body);
expect(res.statusCode).toBe(400);
});
test("should drop 201", async () => {
const jwt = await login();
const res = await request.post(url).set("Cookie", jwt).send(addExam);
expect(res.statusCode).toBe(201);
});
}); });
//describe('GET /api/v1/beer/get', () => { describe("GET /api/v1/review/get", () => {
// const url = '/api/v1/beer/get'; const url = "/api/v1/review/get";
//
// test('should drop 401', async () => { test("should drop 401", async () => {
// const res = await request.get(url).send(); const res = await request.get(url).send();
//
// expect(res.statusCode).toBe(401); expect(res.statusCode).toBe(401);
// }); });
//
// test('should drop 200', async () => { test("should drop 200", async () => {
// const jwt = await login(); const jwt = await login();
// const res = await request.get(url).set('Cookie', jwt).send(); const res = await request.get(url).set("Cookie", jwt).send();
//
// expect(res.statusCode).toBe(200); expect(res.statusCode).toBe(200);
// }); });
//}); });