-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.spec.js
More file actions
74 lines (67 loc) · 2.45 KB
/
server.spec.js
File metadata and controls
74 lines (67 loc) · 2.45 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const request = require("supertest");
const server = require("./server.js");
describe("TS1: Test suite for testing server set-up", () => {
it("TC1: Testing the environment", () => {
expect(process.env.NODE_ENV).toBe("test");
});
it("TC2: Test the default GET request. Should return 200", async () => {
const res = await request(server).get("/");
expect(res.status).toBe(200);
});
it("TC3: Test the response type to be application/json", async () => {
const res = await request(server).get("/");
expect(res.type).toBe("application/json");
});
it("TC4: Test the message in the response.", async () => {
const res = await request(server).get("/");
const { message } = res.body;
expect(message).toBe("The Weather server is up and running!");
});
});
describe("TS2: Test suite for testing /forecast/:place route", () => {
it("TC1: Test the response status for get: forecast.", async () => {
const res = await request(server)
.get("/forecast/Chennai")
.expect(200);
});
it("TC2: Test the data response back from forecast for a place", async () => {
const res = await request(server).get("/forecast/Chennai");
const { city } = res.body;
expect(city).toBe("Chennai");
});
it("TC3: Test the data response back to have a length of 5", async () => {
const res = await request(server).get("/forecast/Chennai");
const { forecasts } = res.body;
expect(forecasts.length).toBe(5);
});
it("TC4: Test the data response back to be of object type currentForecast", async () => {
const currentForecastData = {
city: "Chennai",
day: "Tue",
high: "91",
low: "71",
message: "Sunny",
id: 0
};
const res = await request(server).get("/forecast/Chennai");
const { currentForecast } = res.body;
expect(currentForecast).toMatchObject(currentForecastData);
});
it("TC5: Negative Test the response status for get: forecast.", async () => {
const res = await request(server)
.get("/forecast/Bombay")
.expect(204);
});
});
describe("TS3: Test suite for testing /cities route", () => {
it("TC1: Test the response status for get: cities.", async () => {
const res = await request(server)
.get("/cities")
.expect(200);
});
it("TC2: Test the length of distinct cities obtained. Should be 4", async () => {
const res = await request(server).get("/cities");
const myCities = res.body;
expect(myCities.length).toBe(4);
});
});