-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.test.js
125 lines (115 loc) · 4.15 KB
/
app.test.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const request = require("supertest");
const route = require("./routes/index");
const app = require("./app");
describe("Home Page", () => {
test("home page works", async () => {
await request(app).get("/").expect(200);
});
});
describe("Selection Page", () => {
test("selection page works", async () => {
let data = { name: "Jackie" }
await request(app).post("/selection").send(data).expect(200);
});
});
describe("categoryIndex Function", () => {
test("categoryIndex defined", () => {
expect(route.categoryIndex).toBeDefined();
});
test("categoryIndex works", () => {
expect(route.categoryIndex("general")).toEqual(9);
expect(route.categoryIndex("art")).toEqual(25);
expect(route.categoryIndex("celebrities")).toEqual(26);
expect(route.categoryIndex("film")).toEqual(11);
expect(route.categoryIndex("music")).toEqual(12);
expect(route.categoryIndex("science")).toEqual(17);
expect(route.categoryIndex("sports")).toEqual(21);
});
});
describe("getQuestion Function", () => {
test("getQuestion defined", () => {
expect(route.getQuestion).toBeDefined();
});
test("getQuestion works 1", async () => {
const obj = await route.getQuestion(9, "easy");
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("question"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("correct_answer"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("incorrect_answers"));
});
test("getQuestion works 2", async () => {
const obj = await route.getQuestion(26, "medium");
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("question"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("correct_answer"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("incorrect_answers"));
});
test("getQuestion works 3", async () => {
const obj = await route.getQuestion(17, "hard");
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("question"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("correct_answer"));
expect(JSON.stringify(obj)).toEqual(expect.stringContaining("incorrect_answers"));
});
});
describe("decode Function", () => {
test("decode defined", () => {
expect(route.decode).toBeDefined();
});
test("decode works", () => {
expect(route.decode("I'm")).toEqual("I'm");
expect(route.decode("Ben & Jerry's")).toEqual("Ben & Jerry's");
});
});
describe("makeChoices Function", () => {
test("makeChoices defined", () => {
expect(route.makeChoices).toBeDefined();
});
test("makeChoices works", () => {
expect(route.makeChoices("correct", ["a", "b", "c"]).length).toEqual(4);
expect(route.makeChoices("correct", ["a", "b", "c"])).toContain("correct");
expect(route.makeChoices("correct", ["a", "b", "c"])).toContain("a");
expect(route.makeChoices("correct", ["a", "b", "c"])).toContain("b");
expect(route.makeChoices("correct", ["a", "b", "c"])).toContain("c");
});
});
describe("Question Page", () => {
test("question page works", async () => {
let data = {
category: "general",
difficulty: "easy"
};
await request(app).post("/question").send(data).expect(200);
});
});
describe("getPoints Function", () => {
test("getPoints defined", () => {
expect(route.getPoints).toBeDefined();
});
test("getPoints works", () => {
expect(route.getPoints("easy")).toEqual(10);
expect(route.getPoints("medium")).toEqual(30);
expect(route.getPoints("hard")).toEqual(50);
});
});
describe("Check Page", () => {
test("check page works", async () => {
let data = {
choice: "answer"
};
await request(app).post("/check").send(data).expect(200);
});
test("check page works (more thorough)", async () => {
let qData = {
category: "general",
difficulty: "easy"
};
await request(app).post("/question").send(qData).expect(200);
let aData = {
choice: "answer"
};
await request(app).post("/check").send(aData).expect(200);
});
});
describe("Rankings Page", () => {
test("rankings page works", async () => {
await request(app).get("/rankings").expect(200);
});
});