Appearance
src/__tests__/menu.test.ts โ
From HW1: SliceDrop API ยท original: si-679-f-26-hw1-jessicadonoho/src/__tests__/menu.test.ts ยท all files in this project
ts
import { describe, expect, it } from "vitest";
import request from "supertest";
import { app } from "../app";
describe("GET /menu", () => {
it("returns the whole menu", async () => {
const res = await request(app).get("/menu");
expect(res.status).toBe(200);
expect(res.body).toHaveLength(6);
});
it("filters by category", async () => {
const res = await request(app).get("/menu?category=pizza");
expect(res.status).toBe(200);
expect(res.body).toHaveLength(3);
expect(res.body.every((i: any) => i.category === "pizza")).toBe(true);
});
it("returns an empty array for an unknown category", async () => {
const res = await request(app).get("/menu?category=seafood");
expect(res.status).toBe(200);
expect(res.body).toEqual([]);
});
});
describe("GET /menu/:id", () => {
it("returns the item with its customization options", async () => {
const res = await request(app).get("/menu/hawaiian");
expect(res.status).toBe(200);
expect(res.body.name).toBe("Hawaiian");
expect(res.body.sizes).toHaveLength(3);
expect(res.body.toppings.length).toBeGreaterThan(0);
});
it("404s an unknown id", async () => {
const res = await request(app).get("/menu/sushi");
expect(res.status).toBe(404);
expect(res.body.error).toBeDefined();
});
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40