2019-01-04 01:30:48 +03:00
|
|
|
var childProcess = require('child_process');
|
|
|
|
var request = require('supertest');
|
|
|
|
var scClient = require('socketcluster-client');
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Server', function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
var scServer;
|
2020-08-08 23:26:39 +03:00
|
|
|
beforeAll(function (done) {
|
2019-01-04 01:58:29 +03:00
|
|
|
scServer = childProcess.fork(__dirname + '/../bin/redux-devtools.js');
|
2020-08-08 22:46:01 +03:00
|
|
|
setTimeout(done, 3000);
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
afterAll(function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
if (scServer) {
|
|
|
|
scServer.kill();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Express backend', function () {
|
|
|
|
it('loads main page', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000')
|
|
|
|
.get('/')
|
|
|
|
.expect('Content-Type', /text\/html/)
|
|
|
|
.expect(200)
|
2020-08-08 23:26:39 +03:00
|
|
|
.then(function (res) {
|
2019-01-04 01:58:29 +03:00
|
|
|
expect(res.text).toMatch(/<title>Redux DevTools<\/title>/);
|
2019-01-08 19:35:12 +03:00
|
|
|
done();
|
|
|
|
});
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('resolves an inexistent url', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000/jreerfr/123')
|
|
|
|
.get('/')
|
|
|
|
.expect('Content-Type', /text\/html/)
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Realtime monitoring', function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
var socket, socket2, channel;
|
2020-08-08 23:26:39 +03:00
|
|
|
beforeAll(function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
socket = scClient.connect({ hostname: 'localhost', port: 8000 });
|
|
|
|
socket.connect();
|
2020-08-08 23:26:39 +03:00
|
|
|
socket.on('error', function (error) {
|
2019-01-10 20:23:33 +03:00
|
|
|
console.error('Socket1 error', error); // eslint-disable-line no-console
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
socket2 = scClient.connect({ hostname: 'localhost', port: 8000 });
|
|
|
|
socket2.connect();
|
2020-08-08 23:26:39 +03:00
|
|
|
socket.on('error', function (error) {
|
2019-01-10 20:23:33 +03:00
|
|
|
console.error('Socket2 error', error); // eslint-disable-line no-console
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
afterAll(function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
socket.disconnect();
|
|
|
|
socket2.disconnect();
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should connect', function (done) {
|
|
|
|
socket.on('connect', function (status) {
|
2019-01-08 19:35:12 +03:00
|
|
|
expect(status.id).toBeTruthy();
|
2019-01-04 01:30:48 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should login', function () {
|
|
|
|
socket.emit('login', 'master', function (error, channelName) {
|
2019-01-10 21:51:14 +03:00
|
|
|
if (error) {
|
|
|
|
/* eslint-disable-next-line no-console */
|
|
|
|
console.log(error);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-04 01:30:48 +03:00
|
|
|
expect(channelName).toBe('respond');
|
|
|
|
channel = socket.subscribe(channelName);
|
|
|
|
expect(channel.SUBSCRIBED).toBe('subscribed');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should send message', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
var data = {
|
2019-01-10 21:51:14 +03:00
|
|
|
type: 'ACTION',
|
|
|
|
payload: {
|
2020-08-08 23:26:39 +03:00
|
|
|
todos: 'do some',
|
2019-01-04 01:30:48 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
action: {
|
|
|
|
timestamp: 1483349708506,
|
|
|
|
action: {
|
|
|
|
type: 'ADD_TODO',
|
2020-08-08 23:26:39 +03:00
|
|
|
text: 'hggg',
|
|
|
|
},
|
2019-01-04 01:30:48 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
instanceId: 'tAmA7H5fclyWhvizAAAi',
|
|
|
|
name: 'LoggerInstance',
|
2020-08-08 23:26:39 +03:00
|
|
|
id: 'tAmA7H5fclyWhvizAAAi',
|
2019-01-04 01:30:48 +03:00
|
|
|
};
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
socket2.emit('login', '', function (error, channelName) {
|
2019-01-10 21:51:14 +03:00
|
|
|
if (error) {
|
|
|
|
/* eslint-disable-next-line no-console */
|
|
|
|
console.log(error);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-04 01:30:48 +03:00
|
|
|
expect(channelName).toBe('log');
|
|
|
|
var channel2 = socket2.subscribe(channelName);
|
|
|
|
expect(channel2.SUBSCRIBED).toBe('subscribed');
|
2020-08-08 23:26:39 +03:00
|
|
|
channel2.on('subscribe', function () {
|
|
|
|
channel2.watch(function (message) {
|
2019-01-04 01:30:48 +03:00
|
|
|
expect(message).toEqual(data);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
socket.emit(channelName, data);
|
2019-01-10 21:51:14 +03:00
|
|
|
});
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('REST backend', function () {
|
2019-01-04 01:30:48 +03:00
|
|
|
var id;
|
|
|
|
var report = {
|
|
|
|
type: 'ACTIONS',
|
|
|
|
title: 'Test report',
|
|
|
|
description: 'Test body report',
|
|
|
|
action: 'SOME_FINAL_ACTION',
|
|
|
|
payload: '[{"type":"ADD_TODO","text":"hi"},{"type":"SOME_FINAL_ACTION"}]',
|
2019-01-10 21:51:14 +03:00
|
|
|
preloadedState:
|
|
|
|
'{"todos":[{"text":"Use Redux","completed":false,"id":0}]}',
|
|
|
|
userAgent:
|
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) ' +
|
2020-08-08 23:26:39 +03:00
|
|
|
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36',
|
2019-01-04 01:30:48 +03:00
|
|
|
};
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should add a report', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000')
|
|
|
|
.post('/')
|
|
|
|
.send(report)
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /application\/json/)
|
|
|
|
.expect(200)
|
2020-08-08 23:26:39 +03:00
|
|
|
.then(function (res) {
|
2019-01-04 01:30:48 +03:00
|
|
|
id = res.body.id;
|
2019-01-08 19:35:12 +03:00
|
|
|
expect(id).toBeTruthy();
|
|
|
|
done();
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should get the report', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000')
|
|
|
|
.post('/')
|
|
|
|
.send({
|
|
|
|
op: 'get',
|
2020-08-08 23:26:39 +03:00
|
|
|
id: id,
|
2019-01-04 01:30:48 +03:00
|
|
|
})
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /application\/json/)
|
|
|
|
.expect(200)
|
2020-08-08 23:26:39 +03:00
|
|
|
.then(function (res) {
|
2019-01-08 19:35:12 +03:00
|
|
|
expect.objectContaining(res.body, report);
|
|
|
|
done();
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
it('should list reports', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000')
|
|
|
|
.post('/')
|
|
|
|
.send({
|
2020-08-08 23:26:39 +03:00
|
|
|
op: 'list',
|
2019-01-04 01:30:48 +03:00
|
|
|
})
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /application\/json/)
|
|
|
|
.expect(200)
|
2020-08-08 23:26:39 +03:00
|
|
|
.then(function (res) {
|
2019-01-04 01:30:48 +03:00
|
|
|
expect(res.body.length).toBe(1);
|
|
|
|
expect(res.body[0].id).toBe(id);
|
|
|
|
expect(res.body[0].title).toBe('Test report');
|
2019-01-08 19:35:12 +03:00
|
|
|
expect(res.body[0].added).toBeTruthy();
|
|
|
|
done();
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('GraphQL backend', function () {
|
|
|
|
it('should get the report', function (done) {
|
2019-01-04 01:30:48 +03:00
|
|
|
request('http://localhost:8000')
|
|
|
|
.post('/graphql')
|
|
|
|
.send({
|
2020-08-08 23:26:39 +03:00
|
|
|
query: '{ reports { id, type, title } }',
|
2019-01-04 01:30:48 +03:00
|
|
|
})
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /application\/json/)
|
|
|
|
.expect(200)
|
2020-08-08 23:26:39 +03:00
|
|
|
.then(function (res) {
|
2019-01-04 01:30:48 +03:00
|
|
|
var reports = res.body.data.reports;
|
|
|
|
expect(reports.length).toBe(1);
|
2019-01-08 19:35:12 +03:00
|
|
|
expect(reports[0].id).toBeTruthy();
|
2019-01-04 01:30:48 +03:00
|
|
|
expect(reports[0].title).toBe('Test report');
|
|
|
|
expect(reports[0].type).toBe('ACTIONS');
|
2019-01-08 19:35:12 +03:00
|
|
|
done();
|
2019-01-04 01:30:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|