2024-05-12 21:25:52 +02:00
|
|
|
import supertest from "supertest";
|
|
|
|
import { app } from "../src/app";
|
|
|
|
import { login } from "./auth.test";
|
|
|
|
import { addExam, delExam, editExam } from "../src/validators/beerValidator";
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
const request = supertest(app);
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
describe("POST /api/v1/beer/add", () => {
|
|
|
|
const url = "/api/v1/beer/add";
|
|
|
|
test("should drop 401 error", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const res = await request.post(url).send({});
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 400 ()", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send({});
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 400 (brand)", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
const body: any = { ...addExam };
|
|
|
|
delete body.brand;
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(body);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 201", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(addExam);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(201);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
describe("GET /api/v1/beer/get", () => {
|
|
|
|
const url = "/api/v1/beer/get";
|
2024-05-03 01:46:23 +02:00
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 401", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const res = await request.get(url).send();
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.get(url).set("Cookie", jwt).send();
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
describe("POST /api/v1/beer/del", () => {
|
|
|
|
const url = "/api/v1/beer/del";
|
2024-05-03 01:46:23 +02:00
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 401", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const res = await request.post(url).send();
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 400", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(delExam);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 400", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send({
|
|
|
|
_id: "thisWillNotWork",
|
2024-05-03 01:46:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const req = await request.post("/api/v1/beer/add").set("Cookie", jwt).send(addExam);
|
2024-05-03 01:46:23 +02:00
|
|
|
const id = req.body.data._id;
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send({
|
|
|
|
_id: id,
|
2024-05-03 01:46:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
describe("POST /api/v1/beer/edit", () => {
|
|
|
|
const url = "/api/v1/beer/edit";
|
2024-05-03 01:46:23 +02:00
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 401", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const res = await request.post(url).send();
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 400", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
|
|
|
|
const payload: any = { ...editExam };
|
|
|
|
delete payload._id;
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
|
|
|
|
const payload: any = { ...editExam };
|
|
|
|
delete payload.name;
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
|
|
|
|
const payload: any = { ...editExam };
|
|
|
|
delete payload.degree;
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
|
|
|
|
const payload: any = { ...editExam };
|
|
|
|
delete payload.packaging;
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
|
|
|
|
|
|
|
const payload: any = { ...editExam };
|
|
|
|
delete payload.brand;
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
test("should drop 200", async () => {
|
2024-05-03 01:46:23 +02:00
|
|
|
const jwt = await login();
|
2024-05-12 21:25:52 +02:00
|
|
|
const req = await request.post("/api/v1/beer/add").set("Cookie", jwt).send(addExam);
|
2024-05-03 01:46:23 +02:00
|
|
|
const _id = req.body.data._id;
|
|
|
|
const payload = { ...editExam, _id: _id };
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
let res = await request.post(url).set("Cookie", jwt).send(payload);
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
delete res.body.data._id;
|
|
|
|
delete res.body.data.__v;
|
|
|
|
delete res.body.data.createdAt;
|
|
|
|
delete res.body.data.updatedAt;
|
|
|
|
delete payload._id;
|
|
|
|
|
|
|
|
const eq = JSON.stringify(Object.keys(res.body.data).sort()) === JSON.stringify(Object.keys(payload).sort());
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(eq).toBe(true);
|
|
|
|
});
|
2024-05-12 21:25:52 +02:00
|
|
|
});
|