Skip to content

Commit 40510a4

Browse files
author
Nicolas
committed
merge api.spec.js and parse.spec.js and lint code
1 parent 662a0f2 commit 40510a4

File tree

6 files changed

+185
-255
lines changed

6 files changed

+185
-255
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build
1010
perf.csv
1111
.vscode
1212
.eslintcache
13+
globalConfig.json

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build
1010
perf.csv
1111
.vscode
1212
.eslintcache
13+
globalConfig.json

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build
1010
perf.csv
1111
.vscode
1212
.eslintcache
13+
globalConfig.json

spec/api.spec.js

Lines changed: 144 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
/* eslint-disable */
21
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');
44

5-
process.env.TEST_SUITE = 'api-server';
5+
bindAll();
66

77
describe('api server', () => {
8-
bindAll();
9-
8+
let jwtToken;
109
let applicationId;
1110

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+
});
1417

18+
it('Create Application', async () => {
1519
const response = await axios({
1620
method: 'post',
17-
url: 'http://localhost:3000/api/application',
21+
url: `${API_URL}/api/application`,
1822
headers: {
1923
Authorization: `Bearer ${jwtToken}`,
2024
'Content-Type': 'application/json',
@@ -39,11 +43,9 @@ describe('api server', () => {
3943
});
4044

4145
it('List Application', async () => {
42-
const jwtToken = await getJwtToken();
43-
4446
const response = await axios({
4547
method: 'get',
46-
url: 'http://localhost:3000/api/application',
48+
url: `${API_URL}/api/application`,
4749
headers: {
4850
Authorization: `Bearer ${jwtToken}`,
4951
'Content-Type': 'application/json',
@@ -55,11 +57,9 @@ describe('api server', () => {
5557
});
5658

5759
it('Get Application', async () => {
58-
const jwtToken = await getJwtToken();
59-
6060
const getResponse = await axios({
6161
method: 'get',
62-
url: `http://localhost:3000/api/application/${applicationId}`,
62+
url: `${API_URL}/api/application/${applicationId}`,
6363
headers: {
6464
Authorization: `Bearer ${jwtToken}`,
6565
'Content-Type': 'application/json',
@@ -71,11 +71,9 @@ describe('api server', () => {
7171
});
7272

7373
it('Update Application', async () => {
74-
const jwtToken = await getJwtToken();
75-
7674
const response = await axios({
7775
method: 'put',
78-
url: `http://localhost:3000/api/application/${applicationId}`,
76+
url: `${API_URL}/api/application/${applicationId}`,
7977
headers: {
8078
Authorization: `Bearer ${jwtToken}`,
8179
'Content-Type': 'application/json',
@@ -96,11 +94,9 @@ describe('api server', () => {
9694
});
9795

9896
it('Delete Developer', async () => {
99-
const jwtToken = await getJwtToken();
100-
10197
const response = await axios({
10298
method: 'delete',
103-
url: 'http://localhost:3000/api/developer',
99+
url: `${API_URL}/api/developer`,
104100
headers: {
105101
Authorization: `Bearer ${jwtToken}`,
106102
'Content-Type': 'application/json',
@@ -114,3 +110,131 @@ describe('api server', () => {
114110
expect.assertions(4);
115111
});
116112
});
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

Comments
 (0)