Skip to content

Commit 02dfdd1

Browse files
committed
Set up sample test
1 parent b13fd02 commit 02dfdd1

File tree

1 file changed

+104
-6
lines changed

1 file changed

+104
-6
lines changed

plugins/plugins/tests.js

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
/*global describe,it */
22
var request = require('supertest');
3+
const should = require('should');
4+
5+
const pluginManager = require('../pluginManager.js');
36
var testUtils = require("../../test/testUtils");
47
request = request(testUtils.url);
58

6-
// var APP_KEY = "";
7-
var API_KEY_ADMIN = "";
8-
// var APP_ID = "";
9-
// var DEVICE_ID = "1234567890";
9+
const APP_ID = testUtils.get('APP_ID');
10+
const APP_KEY = testUtils.get('APP_KEY');
11+
const API_KEY_ADMIN = testUtils.get('API_KEY_ADMIN');
12+
13+
const credentials = { api_key: API_KEY_ADMIN, app_id: APP_ID, app_key: APP_KEY };
14+
15+
const sleep = (dur) => {
16+
return new Promise(resolve => setTimeout(resolve, dur));
17+
};
1018

1119
describe('Testing Plugins', function() {
1220
it('should have plugin', function(done) {
13-
API_KEY_ADMIN = testUtils.get("API_KEY_ADMIN");
21+
// API_KEY_ADMIN = testUtils.get("API_KEY_ADMIN");
1422
// APP_ID = testUtils.get("APP_ID");
1523
// APP_KEY = testUtils.get("APP_KEY");
1624
request
@@ -38,4 +46,94 @@ describe('Testing Plugins', function() {
3846
done();
3947
});
4048
});
41-
});
49+
});
50+
51+
describe('Make request without crash', function() {
52+
this.timeout(testUtils.testWaitTimeForDrillEvents * testUtils.testScalingFactor * testUtils.testScalingFactor);
53+
54+
describe('GET request', function() {
55+
it('should success', async() => {
56+
const events = JSON.stringify([{ key: 'test', count: 1 }]);
57+
const resp = await request.get('/i')
58+
.query({
59+
...credentials,
60+
begin_session: 1,
61+
events,
62+
device_id: 'abcd',
63+
}).expect(200);
64+
65+
should(resp.body).not.be.empty();
66+
67+
await sleep(testUtils.testWaitTimeForDrillEvents * testUtils.testScalingFactor);
68+
});
69+
});
70+
71+
describe('verify event', function() {
72+
it('should have event', async() => {
73+
const resp = await request.get('/o')
74+
.query({ ...credentials, method: 'events', event: 'test' })
75+
.expect(200);
76+
77+
should(resp.body).not.be.empty();
78+
});
79+
});
80+
});
81+
82+
describe('Make request with crash', function() {
83+
this.timeout(testUtils.testWaitTimeForDrillEvents * testUtils.testScalingFactor * 5);
84+
85+
describe('GET request', function() {
86+
it('should success', async() => {
87+
const db = await pluginManager.dbConnection();
88+
const app = await db.collection('apps').findOne({ _id: db.ObjectID(APP_ID) }, { blocks: 1 });
89+
should.not.exists(app.blocks);
90+
db.close();
91+
92+
const events = JSON.stringify([{ key: 'test', count: 1 }]);
93+
const crash = JSON.stringify({ _error: 'error', _os: 'android', _name: 'error', _app_version: 'ver', _os_version: '1' });
94+
const resp = await request.get('/i')
95+
.query({
96+
app_key: APP_KEY,
97+
begin_session: 1,
98+
events,
99+
crash,
100+
device_id: 'abcd',
101+
}).expect(200);
102+
103+
should(resp.body).not.be.empty();
104+
105+
await sleep(testUtils.testWaitTimeForDrillEvents * testUtils.testScalingFactor * 3);
106+
});
107+
});
108+
109+
describe('verify crash by db', function() {
110+
it('should have crash', async() => {
111+
const db = await pluginManager.dbConnection();
112+
const crash = await db.collection(`app_crashes${APP_ID}`).findOne({ app_version: 'ver' });
113+
db.close();
114+
115+
should.exists(crash);
116+
});
117+
});
118+
119+
describe('verify crash by req', function() {
120+
it('should have crash', async() => {
121+
const resp = await request.get('/o')
122+
.query({ api_key: API_KEY_ADMIN, app_id: APP_ID, method: 'crashes' })
123+
.expect(200);
124+
125+
should(resp.body).not.be.empty();
126+
should(resp.body.aaData.length).equal(1);
127+
});
128+
});
129+
130+
describe('verify event', function() {
131+
it('should have event', async() => {
132+
const resp = await request.get('/o')
133+
.query({ ...credentials, method: 'events', event: 'test' })
134+
.expect(200);
135+
136+
should(resp.body).not.be.empty();
137+
});
138+
});
139+
});

0 commit comments

Comments
 (0)