-
Notifications
You must be signed in to change notification settings - Fork 33
/
tests.js
131 lines (96 loc) · 2.96 KB
/
tests.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
126
127
128
129
130
131
// CONFIGURATION
let server_base_url = "localhost:3000"
// CONFIGURE MOCHA
import { default as chai, expect } from "chai"
import chaiHttp from "chai-http"
chai.use(chaiHttp)
// TEST SUITES
describe("UNIT tests", function(){
// import pokemon
// create a pokemon
// call the growl function
// import the pokedex
// add a pokemon
// get a pokemon
// delete a pokemon
// update a pokemon
// list pokemons
})
describe("API tests", function(){
// Todo: Exercise 1 - check if server is online
it("server should be online", async function(){
let res = await chai
.request(server_base_url)
.get("/")
.send()
expect(res).to.have.status(200)
expect(res).to.have.header("content-type", "text/html; charset=utf-8")
expect(res).to.be.html
})
// Todo: Exercise 2 - list all pokemons
describe("/api/pokedex/list", function(){
// Todo:
it("list all pokemons", async function(){
let res = await chai
.request(server_base_url)
.get("/api/pokedex/list")
.send()
expect(res).to.have.status(200)
expect(res).to.have.header("content-type", "application/json; charset=utf-8")
expect(res).to.be.json
})
// Todo: Exercise 3 - filter pokemons that are bug type
it("list bug-type pokemons", async function(){
let res = await chai
.request(server_base_url)
.get("/api/pokedex/list")
.send()
expect(res).to.have.status(200)
expect(res).to.have.header("content-type", "application/json; charset=utf-8")
expect(res).to.be.json
// todo: assert that the pokemons are bug type
})
})
describe("/api/pokedex/get", function(){
// Todo: get the pokemon #1; validate the the pokemon name is bulbasaur
// Todo: get the pokemon by name; validate the pokemon name is same
// Todo: get the pokemon #9999; validate status code 404, with error message "Pokemon not found"
})
// Todo: Exercise 4 - add a pokemon, then get the pokemon
describe("/api/pokedex/add", function(){
it("should add a pokemon", async function(){
// first add the pokemon
let res = await chai
.request(server_base_url)
.post("/api/pokedex/add")
.send({
index: 10,
name: "Caterpie",
types: ["bug"],
stats: {
hp: 45,
attack: 30,
defense: 35,
specialAttack: 20,
specialDefense: 20,
speed: 45
}
})
expect(res).to.have.status(200)
expect(res).to.have.header("content-type", "application/json; charset=utf-8")
expect(res).to.be.json
// now get the pokemon
res = await chai
.request(server_base_url)
.get("/api/pokedex/10")
.send()
expect(res).to.have.status(200)
expect(res).to.have.header("content-type", "application/json; charset=utf-8")
expect(res).to.be.json
expect(res.body.name).to.be.equal("Caterpie") // caterpie should be in the pokedex now!
})
it("should update if pokemon already exists", async function(){
})
})
// Todo: Exercise 4 - add a pokemon to the pokedex and the get the pokemon by name
})