Backend: code formatted
This commit is contained in:
@@ -1,166 +1,166 @@
|
||||
import supertest from 'supertest';
|
||||
import { app } from '../src/app';
|
||||
import { login } from './auth.test';
|
||||
import { addExam, delExam, editExam } from '../src/validators/beerValidator';
|
||||
import supertest from "supertest";
|
||||
import { app } from "../src/app";
|
||||
import { login } from "./auth.test";
|
||||
import { addExam, delExam, editExam } from "../src/validators/beerValidator";
|
||||
|
||||
const request = supertest(app);
|
||||
|
||||
describe('POST /api/v1/beer/add', () => {
|
||||
const url = '/api/v1/beer/add';
|
||||
test('should drop 401 error', async () => {
|
||||
describe("POST /api/v1/beer/add", () => {
|
||||
const url = "/api/v1/beer/add";
|
||||
test("should drop 401 error", async () => {
|
||||
const res = await request.post(url).send({});
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('should drop 400 ()', async () => {
|
||||
test("should drop 400 ()", async () => {
|
||||
const jwt = await login();
|
||||
const res = await request.post(url).set('Cookie', jwt).send({});
|
||||
const res = await request.post(url).set("Cookie", jwt).send({});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
test('should drop 400 (brand)', async () => {
|
||||
test("should drop 400 (brand)", async () => {
|
||||
const jwt = await login();
|
||||
const body: any = { ...addExam };
|
||||
delete body.brand;
|
||||
const res = await request.post(url).set('Cookie', jwt).send(body);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(body);
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
test('should drop 201', async () => {
|
||||
test("should drop 201", async () => {
|
||||
const jwt = await login();
|
||||
const res = await request.post(url).set('Cookie', jwt).send(addExam);
|
||||
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';
|
||||
describe("GET /api/v1/beer/get", () => {
|
||||
const url = "/api/v1/beer/get";
|
||||
|
||||
test('should drop 401', async () => {
|
||||
test("should drop 401", async () => {
|
||||
const res = await request.get(url).send();
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/v1/beer/del', () => {
|
||||
const url = '/api/v1/beer/del';
|
||||
describe("POST /api/v1/beer/del", () => {
|
||||
const url = "/api/v1/beer/del";
|
||||
|
||||
test('should drop 401', async () => {
|
||||
test("should drop 401", async () => {
|
||||
const res = await request.post(url).send();
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('should drop 400', async () => {
|
||||
test("should drop 400", async () => {
|
||||
const jwt = await login();
|
||||
const res = await request.post(url).set('Cookie', jwt).send(delExam);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(delExam);
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
test('should drop 400', async () => {
|
||||
test("should drop 400", async () => {
|
||||
const jwt = await login();
|
||||
const res = await request.post(url).set('Cookie', jwt).send({
|
||||
_id: 'thisWillNotWork'
|
||||
const res = await request.post(url).set("Cookie", jwt).send({
|
||||
_id: "thisWillNotWork",
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
const req = await request.post('/api/v1/beer/add').set('Cookie', jwt).send(addExam);
|
||||
const req = await request.post("/api/v1/beer/add").set("Cookie", jwt).send(addExam);
|
||||
const id = req.body.data._id;
|
||||
const res = await request.post(url).set('Cookie', jwt).send({
|
||||
_id: id
|
||||
const res = await request.post(url).set("Cookie", jwt).send({
|
||||
_id: id,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/v1/beer/edit', () => {
|
||||
const url = '/api/v1/beer/edit';
|
||||
describe("POST /api/v1/beer/edit", () => {
|
||||
const url = "/api/v1/beer/edit";
|
||||
|
||||
test('should drop 401', async () => {
|
||||
test("should drop 401", async () => {
|
||||
const res = await request.post(url).send();
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('should drop 400', async () => {
|
||||
test("should drop 400", async () => {
|
||||
const jwt = await login();
|
||||
|
||||
const payload: any = { ...editExam };
|
||||
delete payload._id;
|
||||
|
||||
const res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
|
||||
const payload: any = { ...editExam };
|
||||
delete payload.name;
|
||||
|
||||
const res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
|
||||
const payload: any = { ...editExam };
|
||||
delete payload.degree;
|
||||
|
||||
const res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
|
||||
const payload: any = { ...editExam };
|
||||
delete payload.packaging;
|
||||
|
||||
const res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
|
||||
const payload: any = { ...editExam };
|
||||
delete payload.brand;
|
||||
|
||||
const res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
const res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('should drop 200', async () => {
|
||||
test("should drop 200", async () => {
|
||||
const jwt = await login();
|
||||
const req = await request.post('/api/v1/beer/add').set('Cookie', jwt).send(addExam);
|
||||
const req = await request.post("/api/v1/beer/add").set("Cookie", jwt).send(addExam);
|
||||
const _id = req.body.data._id;
|
||||
const payload = { ...editExam, _id: _id };
|
||||
|
||||
let res = await request.post(url).set('Cookie', jwt).send(payload);
|
||||
let res = await request.post(url).set("Cookie", jwt).send(payload);
|
||||
|
||||
delete res.body.data._id;
|
||||
delete res.body.data.__v;
|
||||
@@ -172,4 +172,4 @@ describe('POST /api/v1/beer/edit', () => {
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(eq).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user