Skip to content

Commit

Permalink
merge api.spec.js and parse.spec.js and lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas committed Jan 13, 2021
1 parent 662a0f2 commit 40510a4
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 255 deletions.
1 change: 1 addition & 0 deletions .eslintignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build
perf.csv
.vscode
.eslintcache
globalConfig.json
1 change: 1 addition & 0 deletions .prettierignore
164 changes: 144 additions & 20 deletions spec/api.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
/* eslint-disable */
const axios = require('axios');
const { bindAll, getJwtToken } = require(`${SPEC_PATH}/helper`);
const { bindAll, getJwtToken } = require('./helper');
const { API_URL } = require('./__mock__/config');

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

describe('api server', () => {
bindAll();

let jwtToken;
let applicationId;

it('Create Application', async () => {
const jwtToken = await getJwtToken();
it('Get JSON web token', async () => {
jwtToken = await getJwtToken();

expect(jwtToken).toBeDefined();
expect.assertions(1);
});

it('Create Application', async () => {
const response = await axios({
method: 'post',
url: 'http://localhost:3000/api/application',
url: `${API_URL}/api/application`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
Expand All @@ -39,11 +43,9 @@ describe('api server', () => {
});

it('List Application', async () => {
const jwtToken = await getJwtToken();

const response = await axios({
method: 'get',
url: 'http://localhost:3000/api/application',
url: `${API_URL}/api/application`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
Expand All @@ -55,11 +57,9 @@ describe('api server', () => {
});

it('Get Application', async () => {
const jwtToken = await getJwtToken();

const getResponse = await axios({
method: 'get',
url: `http://localhost:3000/api/application/${applicationId}`,
url: `${API_URL}/api/application/${applicationId}`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
Expand All @@ -71,11 +71,9 @@ describe('api server', () => {
});

it('Update Application', async () => {
const jwtToken = await getJwtToken();

const response = await axios({
method: 'put',
url: `http://localhost:3000/api/application/${applicationId}`,
url: `${API_URL}/api/application/${applicationId}`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
Expand All @@ -96,11 +94,9 @@ describe('api server', () => {
});

it('Delete Developer', async () => {
const jwtToken = await getJwtToken();

const response = await axios({
method: 'delete',
url: 'http://localhost:3000/api/developer',
url: `${API_URL}/api/developer`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
Expand All @@ -114,3 +110,131 @@ describe('api server', () => {
expect.assertions(4);
});
});

describe('parse custom server', () => {
let sessionToken;
let objectId;

it('Get session token', async () => {
const jwtToken = await getJwtToken();

const response = await axios({
method: 'post',
url: `${API_URL}/api/application`,
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
},
data: {
name: 'toto',
description: 'truc',
apple_store_link: 'https://apple.fr',
google_market_link: 'https://google.fr',
},
});

const parseResponse = await axios({
method: 'get',
url: `${API_URL}/parse/login`,
headers: {
'x-parse-application-id': `test`,
'x-parse-revocable-session': '1',
},
data: {
username: response.data.parse_name,
password: response.data.token,
},
});

expect(parseResponse.data.sessionToken).toBeDefined();
expect.assertions(1);

sessionToken = parseResponse.data.sessionToken;
});

it('Create Item', async () => {
const parseResponse = await axios({
method: 'post',
url: `${API_URL}/parse/classes/GameScore`,
headers: {
'Content-Type': 'application/json',
'x-parse-application-id': `test`,
'x-parse-session-token': sessionToken,
},
data: {
score: 1337,
playerName: 'test9',
cheatMode: false,
},
});

expect(parseResponse.data.score).toBe(1337);
expect(parseResponse.data.playerName).toBe('test9');
expect(parseResponse.data.cheatMode).toBe(false);
expect(parseResponse.data.createdAt).toBeDefined();
expect(parseResponse.data.updatedAt).toBeDefined();
expect(parseResponse.data.objectId).toBeDefined();
expect(parseResponse.data.ACL).toBeUndefined();
expect(parseResponse.data.owner).toBeUndefined();
expect.assertions(8);

objectId = parseResponse.data.objectId;
});

it('Get Items', async () => {
const parseResponse = await axios({
method: 'get',
url: `${API_URL}/parse/classes/GameScore`,
headers: {
'Content-Type': 'application/json',
'x-parse-application-id': `test`,
'x-parse-session-token': sessionToken,
},
});

expect(parseResponse.data.results.length).toBe(1);
expect(parseResponse.data.results[0].playerName).toBe('test9');
expect(parseResponse.data.results[0].objectId).toBe(objectId);
expect(parseResponse.data.results[0].ACL).toBeUndefined();
expect(parseResponse.data.results[0].owner).toBeUndefined();
expect.assertions(5);
});

it('Get Item', async () => {
const parseResponse = await axios({
method: 'get',
url: `${API_URL}/parse/classes/GameScore/${objectId}`,
headers: {
'Content-Type': 'application/json',
'x-parse-application-id': `test`,
'x-parse-session-token': sessionToken,
},
});

expect(parseResponse.data.playerName).toBe('test9');
expect(parseResponse.data.objectId).toBe(objectId);
expect(parseResponse.data.ACL).toBeUndefined();
expect(parseResponse.data.owner).toBeUndefined();
expect.assertions(4);
});

it('Update Item', async () => {
const parseResponse = await axios({
method: 'put',
url: `${API_URL}/parse/classes/GameScore/${objectId}`,
headers: {
'Content-Type': 'application/json',
'x-parse-application-id': `test`,
'x-parse-session-token': sessionToken,
},
data: {
cheatMode: true,
},
});

expect(parseResponse.data.cheatMode).toBe(true);
expect(parseResponse.data.ACL).toBeUndefined();
expect(parseResponse.data.owner).toBeUndefined();
expect.assertions(3);
});
});
Loading

0 comments on commit 40510a4

Please sign in to comment.