-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintegrational_tests.nim
More file actions
160 lines (116 loc) · 4.92 KB
/
Copy pathintegrational_tests.nim
File metadata and controls
160 lines (116 loc) · 4.92 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import asyncdispatch
import json
import httpclient
import tables
import strtabs
import unittest
import times
const
ProtocolVersion = 1
BaseUrl = "http://localhost:5001"
proc buildFalconClient(protocolVersion: int, devId: string = nil, sessionId: string = nil): AsyncHttpClient =
result = newAsyncHttpClient()
result.headers["Falcon-Proto-Version"] = $protocolVersion
if not devId.isNil():
result.headers["Falcon-Device-Id"] = devId
if not sessionId.isNil():
result.headers["Falcon-Session-Id"] = sessionId
suite "Test Error Resilience":
echo "\n General Resilience Behaviour\n"
setup:
var client = buildFalconClient(ProtocolVersion)
test "Test non-existing URL":
let r = waitFor(client.request(BaseUrl & "/bad_url", httpGet, "{}"))
check:
r.status == "404 Not Found"
suite "Test Authentication":
echo "\n Authentication\n"
let devId = $getTime()
setup:
var client = buildFalconClient(ProtocolVersion, devId)
test "Test Login With Device ID (new and existing cases)":
var
r: Response
jr: JsonNode
r = waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}"))
jr = parseJson(r.body)
check:
r.status == "200 OK"
jr.hasKey("sessionId")
jr.hasKey("serverTime")
suite "Test Map":
echo "\n Map\n"
let devId = $getTime()
setup:
var client = buildFalconClient(ProtocolVersion, devId)
test "Get Map And Create (new user)":
let sessionId = parseJson(waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}")).body)["sessionId"].getStr()
client.headers["Falcon-Device-Id"] = ""
client.headers["Falcon-Session-Id"] = sessionId
let map = parseJson(waitFor(client.request(BaseUrl & "/map/get", httpGet, "{}")).body)
check:
map.hasKey("spots")
map.hasKey("serverTime")
test "Get Map And Load (existing user)":
client.headers["Falcon-Session-Id"] = ""
let sessionId = parseJson(waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}")).body)["sessionId"].getStr()
client.headers["Falcon-Session-Id"] = sessionId
let map = parseJson(waitFor(client.request(BaseUrl & "/map/get", httpGet, "{}")).body)
check:
map.hasKey("spots")
map.hasKey("serverTime")
suite "[Eiffel Slot] Spin Test":
echo "\n Eiffel Slot\n"
let devId = $getTime()
setup:
var client = buildFalconClient(ProtocolVersion, devId)
test "[Eiffel Slot] Spinning With Bad JSON":
let r = waitFor(client.request(BaseUrl & "/slot/spin/dreamTowerSlot", httpPost, "asdasdsa}'"))
checkpoint($r)
check r.status == "502 Bad Gateway"
test "[Eiffel Slot] Spin Unauthorized":
let r = waitFor(client.request(BaseUrl & "/slot/spin/dreamTowerSlot", httpPost, $(%*{"bet": 20, "lines": 20})))
check r.status == "502 Bad Gateway"
test "[Eiffel Slot] Spin Success":
let sessionId = parseJson(waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}")).body)["sessionId"].getStr()
client.headers["Falcon-Session-Id"] = sessionId
let r = waitFor(client.request(BaseUrl & "/slot/spin/dreamTowerSlot", httpPost, $(%*{"bet": 20, "lines": 20})))
check r.status == "200 OK"
let jr = parseJson(r.body)
checkpoint($jr)
check:
jr.hasKey("chips")
jr.hasKey("stages")
jr.hasKey("serverTime")
suite "[Balloon Slot] Spin Test":
echo "\n Balloon Slot\n"
let devId = $getTime()
setup:
var client = buildFalconClient(ProtocolVersion, devId)
test "[Balloon Slot] Spin Success":
let sessionId = parseJson(waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}")).body)["sessionId"].getStr()
client.headers["Falcon-Session-Id"] = sessionId
let r = waitFor(client.request(BaseUrl & "/slot/spin/balloonSlot", httpPost, $(%*{"bet": 20, "lines": 15})))
check r.status == "200 OK"
let jr = parseJson(r.body)
checkpoint($jr)
check:
jr.hasKey("stages")
jr.hasKey("serverTime")
suite "[Candy Slot] Spin Test":
echo "\n Candy Slot\n"
let devId = $getTime()
setup:
var client = buildFalconClient(ProtocolVersion, devId)
test "[Candy Slot] Spin Success":
let sessionId = parseJson(waitFor(client.request(BaseUrl & "/auth/login/device", httpPost, "{}")).body)["sessionId"].getStr()
client.headers["Falcon-Session-Id"] = sessionId
let r = waitFor(client.request(BaseUrl & "/slot/spin/candySlot", httpPost, $(%*{"bet": 20, "lines": 15})))
check r.status == "200 OK"
let jr = parseJson(r.body)
checkpoint($jr)
check:
jr.hasKey("stages")
jr.hasKey("serverTime")
jr["stages"].len() >= 1
echo ""