From c6b3efad4ee92c0c0ad82d7e84c06368acb6afad Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Thu, 16 May 2024 18:05:05 +0200 Subject: [PATCH] Added: note in backend --- api/src/models/Review.ts | 5 +++++ api/src/validators/reviewValidator.ts | 4 +++- api/tests/review.test.ts | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/models/Review.ts b/api/src/models/Review.ts index 7c39149..36671b5 100644 --- a/api/src/models/Review.ts +++ b/api/src/models/Review.ts @@ -28,6 +28,11 @@ const schema = new Schema( type: Boolean, required: true, }, + note: { + type: String, + required: false, + default: "" + }, beer_id: { type: String, required: true, diff --git a/api/src/validators/reviewValidator.ts b/api/src/validators/reviewValidator.ts index 03fe14c..213020f 100644 --- a/api/src/validators/reviewValidator.ts +++ b/api/src/validators/reviewValidator.ts @@ -20,7 +20,8 @@ export const add = yup.object({ packaging: yup.number().min(1).max(5).required(), sourness: yup.boolean().required(), would_again: yup.boolean().required(), - user_id: yup.string().notRequired() + user_id: yup.string().notRequired(), + note: yup.string().notRequired() }); export interface IReview extends yup.InferType, mongooseAddition {} export const addExam: IReview = { @@ -31,6 +32,7 @@ export const addExam: IReview = { packaging: 3, sourness: false, would_again: true, + note: "Pretty good beer" }; // Remove diff --git a/api/tests/review.test.ts b/api/tests/review.test.ts index 68801f2..f504aac 100644 --- a/api/tests/review.test.ts +++ b/api/tests/review.test.ts @@ -73,6 +73,15 @@ describe("POST /api/v1/review/add", () => { expect(res.statusCode).toBe(400); }); + test("should drop 201 (missing note)", async () => { + const jwt = await login(); + const body: any = { ...addExam }; + delete body.note; + const res = await request.post(url).set("Cookie", jwt).send(body); + + expect(res.statusCode).toBe(201); + }) + test("should drop 201", async () => { const jwt = await login(); const res = await request.post(url).set("Cookie", jwt).send(addExam);