|
1 | 1 | import request from "supertest"; |
| 2 | +import { jest } from "@jest/globals"; |
| 3 | +// import supertest from "supertest"; |
2 | 4 |
|
3 | 5 | import app from "./app.js"; |
4 | 6 |
|
5 | | -describe("GET /users", function () { |
6 | | - test("gives us back 200, with a message", async function () { |
7 | | - const expectedBody = { |
8 | | - message: "I wish we had some information to give you ☹️" |
9 | | - }; |
10 | | - const actual = await request(app).get("/users"); |
11 | | - expect(actual.body).toStrictEqual(expectedBody); |
12 | | - expect(actual.statusCode).toBe(200); |
| 7 | +jest.setTimeout(10000); |
| 8 | +//JOINCLEAN ROUTES |
| 9 | +//Test joinclean routes GET, POST, PUT, DELETE |
| 10 | +describe("Tests for /joinclean route", () => { |
| 11 | + describe("Tests for GET /joinclean", () => { |
| 12 | + test("GET /joinclean returns 200 status code", async () => { |
| 13 | + let res = await request(app).get("/joinclean"); |
| 14 | + expect(res.statusCode).toEqual(200); |
| 15 | + }); |
| 16 | + |
| 17 | + test("GET /joinclean returns json content", async () => { |
| 18 | + let res = await request(app).get("/joinclean"); |
| 19 | + expect(res.headers["content-type"]).toEqual( |
| 20 | + expect.stringContaining("json") |
| 21 | + ); |
| 22 | + }); |
| 23 | + test("GET /joinclean returns an object", async () => { |
| 24 | + let res = await request(app).get("/joinclean"); |
| 25 | + expect(res._body).toEqual( |
| 26 | + expect.objectContaining({ |
| 27 | + success: true, |
| 28 | + payload: expect.any(Array), |
| 29 | + }) |
| 30 | + ); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe("Tests for POST /joinclean", () => { |
| 35 | + test("POST /joinclean returns a 200 status code", async () => { |
| 36 | + const res = await request(app).post("/joinclean").send({ |
| 37 | + name: "Any name", |
| 38 | + comments: "A comment", |
| 39 | + }); |
| 40 | + expect(res.statusCode).toEqual(200); |
| 41 | + }); |
| 42 | + test("POST /joinclean method is POST", async () => { |
| 43 | + const res = await request(app).post("/joinclean").send({ |
| 44 | + name: "Any name", |
| 45 | + comments: "A comment", |
| 46 | + }); |
| 47 | + expect(res.req.method).toEqual("POST"); |
| 48 | + }); |
| 49 | + test("POST /joinclean object is to /joinclean", async () => { |
| 50 | + const res = await request(app).post("/joinclean").send({ |
| 51 | + name: "Any name", |
| 52 | + comments: "A comment", |
| 53 | + }); |
| 54 | + expect(res.req.path).toEqual("/joinclean"); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + // console.log("this is the raw headers ", res.req); |
| 59 | + // expect(res.req.method).toEqual("POST"); |
| 60 | + // expect(res.req.path).toEqual("/joinclean"); |
| 61 | + // expect(res.rawHeaders).toEqual( |
| 62 | + // expect.arrayContaining(expect.stringContaining("json")) |
| 63 | + // ); |
| 64 | + // expect(res._data).toEqual( |
| 65 | + // objectContaining({ name: "Any name", comments: "A comment" }) |
| 66 | + // ); |
| 67 | + describe("Tests for PUT /joinclean", () => { |
| 68 | + test("PUT /joinclean returns a 200 status code", async () => { |
| 69 | + const res = await request(app).put("/joinclean/1").send({ |
| 70 | + name: "Any name", |
| 71 | + comments: "A comment", |
| 72 | + }); |
| 73 | + //console.log(res.body.payload) |
| 74 | + expect(res.statusCode).toEqual(200); |
| 75 | + }); |
| 76 | + }); |
| 77 | + describe("Tests for DELETE /joinclean", () => { |
| 78 | + test("DELETE /joinclean returns the correct status code", async () => { |
| 79 | + const res = await request(app).delete("/joinclean/1"); |
| 80 | + expect(res.statusCode).toEqual(200); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
| 84 | + |
| 85 | + |
| 86 | +//LOGCLEAN ROUTES |
| 87 | +// can write tests for GET, POST, PUT |
| 88 | +describe("Tests for /logclean route", () => { |
| 89 | + describe("Tests for GET /logclean ", () => { |
| 90 | + test("GET /logclean returns a 200 status code", async () => { |
| 91 | + let res = await request(app).get("/logclean"); |
| 92 | + expect(res.statusCode).toEqual(200); |
| 93 | + }); |
| 94 | + test("GET /logclean returns json content", async () => { |
| 95 | + let res = await request(app).get("/logclean"); |
| 96 | + expect(res.headers["content-type"]).toEqual( |
| 97 | + expect.stringContaining("json") |
| 98 | + ); |
| 99 | + }); |
| 100 | + test("GET /logclean returns an object", async () => { |
| 101 | + let res = await request(app).get("/logclean"); |
| 102 | + expect(res._body).toEqual( |
| 103 | + expect.objectContaining({ |
| 104 | + success: true, |
| 105 | + payload: expect.any(Array), |
| 106 | + }) |
| 107 | + ); |
| 108 | + }); |
| 109 | + }); |
| 110 | + describe("Tests for POST /logclean ", () => { |
| 111 | + test("POST /logclean returns a 200 status code", async () => { |
| 112 | + const res = await request(app).post("/logclean").send({ |
| 113 | + cleanname: "Test Clean", |
| 114 | + bags: 1, |
| 115 | + volunteers: 1, |
| 116 | + }); |
| 117 | + expect(res.statusCode).toEqual(200); |
| 118 | + }); |
| 119 | + test("POST /logclean method is POST", async () => { |
| 120 | + const res = await request(app).post("/logclean").send({ |
| 121 | + cleanname: "Test Clean", |
| 122 | + bags: 1, |
| 123 | + volunteers: 1, |
| 124 | + }); |
| 125 | + expect(res.req.method).toEqual("POST"); |
| 126 | + }); |
| 127 | + test("POST /logclean object is to /logclean", async () => { |
| 128 | + const res = await request(app).post("/logclean").send({ |
| 129 | + cleanname: "Test Clean", |
| 130 | + bags: 1, |
| 131 | + volunteers: 1, |
| 132 | + }); |
| 133 | + expect(res.req.path).toEqual("/logclean"); |
| 134 | + }); |
| 135 | + }); |
| 136 | + describe("Tests for PUT /logclean ", () => { |
| 137 | + test("PUT /logclean returns a 200 status code", async () => { |
| 138 | + const res = await request(app).put("/logclean/1").send({ |
| 139 | + cleanname: "Updated Test Clean", |
| 140 | + bags: 2, |
| 141 | + volunteers: 2, |
| 142 | + }); |
| 143 | + expect(res.statusCode).toEqual(200); |
| 144 | + }); |
| 145 | + }); |
| 146 | +}); |
| 147 | + |
| 148 | + |
| 149 | +// STARTCLEAN ROUTES |
| 150 | +//can write tests for GET, POST |
| 151 | +describe("Tests for /startclean route", () => { |
| 152 | + describe("Tests for GET /logclean ", () => { |
| 153 | + test("GET /startclean returns 200 status code", async () => { |
| 154 | + let res = await request(app).get("/startclean"); |
| 155 | + |
| 156 | + expect(res.statusCode).toEqual(200); |
| 157 | + }); |
| 158 | + test("GET /startclean returns json content", async () => { |
| 159 | + let res = await request(app).get("/startclean"); |
| 160 | + expect(res.headers["content-type"]).toEqual( |
| 161 | + expect.stringContaining("json") |
| 162 | + ); |
| 163 | + }); |
| 164 | + test("GET /startclean returns an object", async () => { |
| 165 | + let res = await request(app).get("/startclean"); |
| 166 | + expect(res._body).toEqual( |
| 167 | + expect.objectContaining({ |
| 168 | + success: true, |
| 169 | + payload: expect.any(Array), |
| 170 | + }) |
| 171 | + ); |
| 172 | + }); |
| 173 | + }); |
| 174 | + |
| 175 | + describe("Tests for POST /logclean ", () => { |
| 176 | + test("POST /startclean returns a 200 status code and confirmation of an object being posted", async () => { |
| 177 | + const res = await request(app).post("/startclean").send({ |
| 178 | + cleanName: "New Clean Name", |
| 179 | + location: "Some Location", |
| 180 | + date: "22.09.22", |
| 181 | + startTime: "12:00", |
| 182 | + endTime: "13:00", |
| 183 | + host: "Some Host", |
| 184 | + notes: "A Note", |
| 185 | + latitude: 74.87603594928817, |
| 186 | + longitude: -40.301351746354406, |
| 187 | + }); |
| 188 | + expect(res.statusCode).toEqual(200); |
| 189 | + }); |
| 190 | + test("POST /startclean method is POST", async () => { |
| 191 | + const res = await request(app).post("/startclean").send({ |
| 192 | + cleanName: "New Clean Name", |
| 193 | + location: "Some Location", |
| 194 | + date: "22.09.22", |
| 195 | + startTime: "12:00", |
| 196 | + endTime: "13:00", |
| 197 | + host: "Some Host", |
| 198 | + notes: "A Note", |
| 199 | + latitude: 74.87603594928817, |
| 200 | + longitude: -40.301351746354406, |
| 201 | + }); |
| 202 | + expect(res.req.method).toEqual("POST"); |
| 203 | + }); |
| 204 | + test("POST /startclean object is to /startclean", async () => { |
| 205 | + const res = await request(app).post("/startclean").send({ |
| 206 | + cleanName: "New Clean Name", |
| 207 | + location: "Some Location", |
| 208 | + date: "22.09.22", |
| 209 | + startTime: "12:00", |
| 210 | + endTime: "13:00", |
| 211 | + host: "Some Host", |
| 212 | + notes: "A Note", |
| 213 | + latitude: 74.87603594928817, |
| 214 | + longitude: -40.301351746354406, |
| 215 | + }); |
| 216 | + expect(res.req.path).toEqual("/startclean"); |
| 217 | + }); |
13 | 218 | }); |
14 | 219 | }); |
0 commit comments