Added: tests for reviews, Reviews GET API endpoint; Fixed: tests for beers
This commit is contained in:
parent
2168756afd
commit
312809f34f
@ -10,6 +10,7 @@ import validate from "../middlewares/validateRequest";
|
||||
import valMulter from "../middlewares/validateMulterRequest";
|
||||
import * as AuthVal from "../validators/authValidator";
|
||||
import * as BVal from "../validators/beerValidator";
|
||||
import * as RVal from "../validators/reviewValidator";
|
||||
|
||||
const upload = multer({ dest: path.resolve(__dirname, "../../uploads") });
|
||||
|
||||
@ -35,6 +36,7 @@ router.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;
|
||||
|
@ -19,6 +19,33 @@ describe("POST /api/v1/beer/add", () => {
|
||||
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 () => {
|
||||
const jwt = await login();
|
||||
const body: any = { ...addExam };
|
||||
|
@ -1,7 +1,7 @@
|
||||
import supertest from "supertest";
|
||||
import { app } from "../src/app";
|
||||
import { login } from "./auth.test";
|
||||
//import { addExam, delExam, editExam } from '../src/validators/beerValidator';
|
||||
import { addExam, delExam } from "../src/validators/reviewValidator";
|
||||
|
||||
const request = supertest(app);
|
||||
|
||||
@ -16,32 +16,84 @@ describe("POST /api/v1/review/add", () => {
|
||||
const jwt = await login();
|
||||
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);
|
||||
});
|
||||
|
||||
// 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);
|
||||
// });
|
||||
test("should drop 400 (bitter_sweetness)", async () => {
|
||||
const jwt = await login();
|
||||
const body: any = { ...addExam };
|
||||
delete body.bitter_sweetness;
|
||||
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', () => {
|
||||
// const url = '/api/v1/beer/get';
|
||||
//
|
||||
// test('should drop 401', async () => {
|
||||
// const res = await request.get(url).send();
|
||||
//
|
||||
// expect(res.statusCode).toBe(401);
|
||||
// });
|
||||
//
|
||||
// test('should drop 200', async () => {
|
||||
// const jwt = await login();
|
||||
// const res = await request.get(url).set('Cookie', jwt).send();
|
||||
//
|
||||
// expect(res.statusCode).toBe(200);
|
||||
// });
|
||||
//});
|
||||
describe("GET /api/v1/review/get", () => {
|
||||
const url = "/api/v1/review/get";
|
||||
|
||||
test("should drop 401", async () => {
|
||||
const res = await request.get(url).send();
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
const res = await request.get(url).set("Cookie", jwt).send();
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user