-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
52 lines (44 loc) · 1.61 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
const test = require("tape")
const request = require("supertest")
const {server} = require("./server.js")
const gameId = 0 // will exist after 1st valid game CREATE.
test("malformed board", t => {
const malformedBoard = null
request(server).post("/games").send(malformedBoard)
.expect(400, "Invalid board").end(t.end)
})
test("valid board", t => {
const validBoard = require("./files/test-board-1.json")
request(server).post("/games").send(validBoard)
.expect(201, {gameId: 0}).end(t.end)
})
test("malformed dict", t => {
const malformedDict = null
request(server).put(`/games/${gameId}/dict`).send(malformedDict)
.expect(400, "Invalid dictionary").end(t.end)
})
test("valid dict", t => {
const validDict = require("./files/dictionary.json")
request(server).put(`/games/${gameId}/dict`).send(validDict)
.expect(204).end(t.end)
})
test("malformed move", t => {
const malformedMove = null
request(server).post(`/games/${gameId}/moves`).send(malformedMove)
.expect(400, "Move must be list of 3+ tiles").end(t.end)
})
test("disallowed move", t => {
const disallowedMove = [12,15,1,4] // "LOAD"
request(server).post(`/games/${gameId}/moves`).send(disallowedMove)
.expect(403, "Move is not allowed on board").end(t.end)
})
test("allowed move", t => {
const allowedMove = [6,1,2] // "FAB"
request(server).post(`/games/${gameId}/moves`).send(allowedMove)
.expect(201, {moveId: 0, points: 1}).end(t.end)
})
test("duplicate move", t => {
const allowedMove = [6,1,2] // "FAB"
request(server).post(`/games/${gameId}/moves`).send(allowedMove)
.expect(403, "Move already played").end(t.end)
})