1
- /* eslint-disable */
2
1
const axios = require ( 'axios' ) ;
3
- const { bindAll, getJwtToken } = require ( `${ SPEC_PATH } /helper` ) ;
2
+ const { bindAll, getJwtToken } = require ( './helper' ) ;
3
+ const { API_URL } = require ( './__mock__/config' ) ;
4
4
5
- process . env . TEST_SUITE = 'api-server' ;
5
+ bindAll ( ) ;
6
6
7
7
describe ( 'api server' , ( ) => {
8
- bindAll ( ) ;
9
-
8
+ let jwtToken ;
10
9
let applicationId ;
11
10
12
- it ( 'Create Application' , async ( ) => {
13
- const jwtToken = await getJwtToken ( ) ;
11
+ it ( 'Get JSON web token' , async ( ) => {
12
+ jwtToken = await getJwtToken ( ) ;
13
+
14
+ expect ( jwtToken ) . toBeDefined ( ) ;
15
+ expect . assertions ( 1 ) ;
16
+ } ) ;
14
17
18
+ it ( 'Create Application' , async ( ) => {
15
19
const response = await axios ( {
16
20
method : 'post' ,
17
- url : 'http://localhost:3000/ api/application' ,
21
+ url : ` ${ API_URL } / api/application` ,
18
22
headers : {
19
23
Authorization : `Bearer ${ jwtToken } ` ,
20
24
'Content-Type' : 'application/json' ,
@@ -39,11 +43,9 @@ describe('api server', () => {
39
43
} ) ;
40
44
41
45
it ( 'List Application' , async ( ) => {
42
- const jwtToken = await getJwtToken ( ) ;
43
-
44
46
const response = await axios ( {
45
47
method : 'get' ,
46
- url : 'http://localhost:3000/ api/application' ,
48
+ url : ` ${ API_URL } / api/application` ,
47
49
headers : {
48
50
Authorization : `Bearer ${ jwtToken } ` ,
49
51
'Content-Type' : 'application/json' ,
@@ -55,11 +57,9 @@ describe('api server', () => {
55
57
} ) ;
56
58
57
59
it ( 'Get Application' , async ( ) => {
58
- const jwtToken = await getJwtToken ( ) ;
59
-
60
60
const getResponse = await axios ( {
61
61
method : 'get' ,
62
- url : `http://localhost:3000 /api/application/${ applicationId } ` ,
62
+ url : `${ API_URL } /api/application/${ applicationId } ` ,
63
63
headers : {
64
64
Authorization : `Bearer ${ jwtToken } ` ,
65
65
'Content-Type' : 'application/json' ,
@@ -71,11 +71,9 @@ describe('api server', () => {
71
71
} ) ;
72
72
73
73
it ( 'Update Application' , async ( ) => {
74
- const jwtToken = await getJwtToken ( ) ;
75
-
76
74
const response = await axios ( {
77
75
method : 'put' ,
78
- url : `http://localhost:3000 /api/application/${ applicationId } ` ,
76
+ url : `${ API_URL } /api/application/${ applicationId } ` ,
79
77
headers : {
80
78
Authorization : `Bearer ${ jwtToken } ` ,
81
79
'Content-Type' : 'application/json' ,
@@ -96,11 +94,9 @@ describe('api server', () => {
96
94
} ) ;
97
95
98
96
it ( 'Delete Developer' , async ( ) => {
99
- const jwtToken = await getJwtToken ( ) ;
100
-
101
97
const response = await axios ( {
102
98
method : 'delete' ,
103
- url : 'http://localhost:3000/ api/developer' ,
99
+ url : ` ${ API_URL } / api/developer` ,
104
100
headers : {
105
101
Authorization : `Bearer ${ jwtToken } ` ,
106
102
'Content-Type' : 'application/json' ,
@@ -114,3 +110,131 @@ describe('api server', () => {
114
110
expect . assertions ( 4 ) ;
115
111
} ) ;
116
112
} ) ;
113
+
114
+ describe ( 'parse custom server' , ( ) => {
115
+ let sessionToken ;
116
+ let objectId ;
117
+
118
+ it ( 'Get session token' , async ( ) => {
119
+ const jwtToken = await getJwtToken ( ) ;
120
+
121
+ const response = await axios ( {
122
+ method : 'post' ,
123
+ url : `${ API_URL } /api/application` ,
124
+ headers : {
125
+ Authorization : `Bearer ${ jwtToken } ` ,
126
+ 'Content-Type' : 'application/json' ,
127
+ } ,
128
+ data : {
129
+ name : 'toto' ,
130
+ description : 'truc' ,
131
+ apple_store_link : 'https://apple.fr' ,
132
+ google_market_link : 'https://google.fr' ,
133
+ } ,
134
+ } ) ;
135
+
136
+ const parseResponse = await axios ( {
137
+ method : 'get' ,
138
+ url : `${ API_URL } /parse/login` ,
139
+ headers : {
140
+ 'x-parse-application-id' : `test` ,
141
+ 'x-parse-revocable-session' : '1' ,
142
+ } ,
143
+ data : {
144
+ username : response . data . parse_name ,
145
+ password : response . data . token ,
146
+ } ,
147
+ } ) ;
148
+
149
+ expect ( parseResponse . data . sessionToken ) . toBeDefined ( ) ;
150
+ expect . assertions ( 1 ) ;
151
+
152
+ sessionToken = parseResponse . data . sessionToken ;
153
+ } ) ;
154
+
155
+ it ( 'Create Item' , async ( ) => {
156
+ const parseResponse = await axios ( {
157
+ method : 'post' ,
158
+ url : `${ API_URL } /parse/classes/GameScore` ,
159
+ headers : {
160
+ 'Content-Type' : 'application/json' ,
161
+ 'x-parse-application-id' : `test` ,
162
+ 'x-parse-session-token' : sessionToken ,
163
+ } ,
164
+ data : {
165
+ score : 1337 ,
166
+ playerName : 'test9' ,
167
+ cheatMode : false ,
168
+ } ,
169
+ } ) ;
170
+
171
+ expect ( parseResponse . data . score ) . toBe ( 1337 ) ;
172
+ expect ( parseResponse . data . playerName ) . toBe ( 'test9' ) ;
173
+ expect ( parseResponse . data . cheatMode ) . toBe ( false ) ;
174
+ expect ( parseResponse . data . createdAt ) . toBeDefined ( ) ;
175
+ expect ( parseResponse . data . updatedAt ) . toBeDefined ( ) ;
176
+ expect ( parseResponse . data . objectId ) . toBeDefined ( ) ;
177
+ expect ( parseResponse . data . ACL ) . toBeUndefined ( ) ;
178
+ expect ( parseResponse . data . owner ) . toBeUndefined ( ) ;
179
+ expect . assertions ( 8 ) ;
180
+
181
+ objectId = parseResponse . data . objectId ;
182
+ } ) ;
183
+
184
+ it ( 'Get Items' , async ( ) => {
185
+ const parseResponse = await axios ( {
186
+ method : 'get' ,
187
+ url : `${ API_URL } /parse/classes/GameScore` ,
188
+ headers : {
189
+ 'Content-Type' : 'application/json' ,
190
+ 'x-parse-application-id' : `test` ,
191
+ 'x-parse-session-token' : sessionToken ,
192
+ } ,
193
+ } ) ;
194
+
195
+ expect ( parseResponse . data . results . length ) . toBe ( 1 ) ;
196
+ expect ( parseResponse . data . results [ 0 ] . playerName ) . toBe ( 'test9' ) ;
197
+ expect ( parseResponse . data . results [ 0 ] . objectId ) . toBe ( objectId ) ;
198
+ expect ( parseResponse . data . results [ 0 ] . ACL ) . toBeUndefined ( ) ;
199
+ expect ( parseResponse . data . results [ 0 ] . owner ) . toBeUndefined ( ) ;
200
+ expect . assertions ( 5 ) ;
201
+ } ) ;
202
+
203
+ it ( 'Get Item' , async ( ) => {
204
+ const parseResponse = await axios ( {
205
+ method : 'get' ,
206
+ url : `${ API_URL } /parse/classes/GameScore/${ objectId } ` ,
207
+ headers : {
208
+ 'Content-Type' : 'application/json' ,
209
+ 'x-parse-application-id' : `test` ,
210
+ 'x-parse-session-token' : sessionToken ,
211
+ } ,
212
+ } ) ;
213
+
214
+ expect ( parseResponse . data . playerName ) . toBe ( 'test9' ) ;
215
+ expect ( parseResponse . data . objectId ) . toBe ( objectId ) ;
216
+ expect ( parseResponse . data . ACL ) . toBeUndefined ( ) ;
217
+ expect ( parseResponse . data . owner ) . toBeUndefined ( ) ;
218
+ expect . assertions ( 4 ) ;
219
+ } ) ;
220
+
221
+ it ( 'Update Item' , async ( ) => {
222
+ const parseResponse = await axios ( {
223
+ method : 'put' ,
224
+ url : `${ API_URL } /parse/classes/GameScore/${ objectId } ` ,
225
+ headers : {
226
+ 'Content-Type' : 'application/json' ,
227
+ 'x-parse-application-id' : `test` ,
228
+ 'x-parse-session-token' : sessionToken ,
229
+ } ,
230
+ data : {
231
+ cheatMode : true ,
232
+ } ,
233
+ } ) ;
234
+
235
+ expect ( parseResponse . data . cheatMode ) . toBe ( true ) ;
236
+ expect ( parseResponse . data . ACL ) . toBeUndefined ( ) ;
237
+ expect ( parseResponse . data . owner ) . toBeUndefined ( ) ;
238
+ expect . assertions ( 3 ) ;
239
+ } ) ;
240
+ } ) ;
0 commit comments