reduce usage of io.emit in tests

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 2ae855678a
commit 4f31dec82c

@ -596,7 +596,7 @@ describe('Controllers', function () {
user.create({ username: 'revokeme', password: 'barbar' }, function (err, _uid) { user.create({ username: 'revokeme', password: 'barbar' }, function (err, _uid) {
assert.ifError(err); assert.ifError(err);
uid = _uid; uid = _uid;
helpers.loginUser('revokeme', 'barbar', function (err, _jar, io, _csrf_token) { helpers.loginUser('revokeme', 'barbar', function (err, _jar, _csrf_token) {
assert.ifError(err); assert.ifError(err);
jar = _jar; jar = _jar;
csrf_token = _csrf_token; csrf_token = _csrf_token;

@ -1138,7 +1138,7 @@ describe('Groups', function () {
}); });
it('should error if user is not owner of group', function (done) { it('should error if user is not owner of group', function (done) {
helpers.loginUser('regularuser', '123456', function (err, jar, io, csrf_token) { helpers.loginUser('regularuser', '123456', function (err, jar, csrf_token) {
assert.ifError(err); assert.ifError(err);
helpers.uploadFile(nconf.get('url') + '/api/groups/uploadpicture', logoPath, { params: JSON.stringify({ groupName: 'Test' }) }, jar, csrf_token, function (err, res, body) { helpers.uploadFile(nconf.get('url') + '/api/groups/uploadpicture', logoPath, { params: JSON.stringify({ groupName: 'Test' }) }, jar, csrf_token, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
@ -1150,7 +1150,7 @@ describe('Groups', function () {
}); });
it('should upload group cover with api route', function (done) { it('should upload group cover with api route', function (done) {
helpers.loginUser('admin', '123456', function (err, jar, io, csrf_token) { helpers.loginUser('admin', '123456', function (err, jar, csrf_token) {
assert.ifError(err); assert.ifError(err);
helpers.uploadFile(nconf.get('url') + '/api/groups/uploadpicture', logoPath, { params: JSON.stringify({ groupName: 'Test' }) }, jar, csrf_token, function (err, res, body) { helpers.uploadFile(nconf.get('url') + '/api/groups/uploadpicture', logoPath, { params: JSON.stringify({ groupName: 'Test' }) }, jar, csrf_token, function (err, res, body) {
assert.ifError(err); assert.ifError(err);

@ -36,9 +36,7 @@ helpers.loginUser = function (username, password, callback) {
if (err || res.statusCode !== 200) { if (err || res.statusCode !== 200) {
return callback(err || new Error('[[error:invalid-response]]')); return callback(err || new Error('[[error:invalid-response]]'));
} }
helpers.connectSocketIO(res, function (err, io) { callback(null, jar, body.csrf_token);
callback(err, jar, io, body.csrf_token);
});
}); });
}); });
}; };

@ -1,53 +0,0 @@
'use strict';
/* global require, after, before*/
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var db = require('./mocks/databasemock');
var logger = require('../src/logger');
var index = require('../src/socket.io');
var meta = require('../src/meta');
var user = require('../src/user');
var helpers = require('./helpers');
describe('logger', function () {
var jar;
var io;
before(function (done) {
user.create({ username: 'loggeruser', password: '123456' }, function (err) {
assert.ifError(err);
helpers.loginUser('loggeruser', '123456', function (err, _jar, _io) {
assert.ifError(err);
jar = _jar;
io = _io;
done();
});
});
});
it('should enable logging', function (done) {
meta.config.loggerStatus = 1;
meta.config.loggerIOStatus = 1;
var loggerPath = path.join(__dirname, '..', 'logs', 'logger.log');
logger.monitorConfig({ io: index.server }, { key: 'loggerPath', value: loggerPath });
setTimeout(function () {
io.emit('meta.rooms.enter', { enter: 'recent_topics' }, function (err) {
assert.ifError(err);
fs.readFile(loggerPath, 'utf-8', function (err, content) {
assert.ifError(err);
assert(content);
done();
});
});
}, 500);
});
after(function (done) {
meta.config.loggerStatus = 0;
meta.config.loggerIOStatus = 0;
done();
});
});

@ -576,7 +576,7 @@ describe('socket.io', function () {
}); });
}); });
it('shoudl delete all events', function (done) { it('should delete all events', function (done) {
socketAdmin.deleteAllEvents({ uid: adminUid }, {}, function (err) { socketAdmin.deleteAllEvents({ uid: adminUid }, {}, function (err) {
assert.ifError(err); assert.ifError(err);
db.sortedSetCard('events:time', function (err, count) { db.sortedSetCard('events:time', function (err, count) {
@ -586,5 +586,34 @@ describe('socket.io', function () {
}); });
}); });
}); });
});
describe('logger', function () {
var logger = require('../src/logger');
var index = require('../src/socket.io');
var fs = require('fs');
var path = require('path');
it('should enable logging', function (done) {
meta.config.loggerStatus = 1;
meta.config.loggerIOStatus = 1;
var loggerPath = path.join(__dirname, '..', 'logs', 'logger.log');
logger.monitorConfig({ io: index.server }, { key: 'loggerPath', value: loggerPath });
setTimeout(function () {
io.emit('meta.rooms.enter', { enter: 'recent_topics' }, function (err) {
assert.ifError(err);
fs.readFile(loggerPath, 'utf-8', function (err, content) {
assert.ifError(err);
assert(content);
done();
});
});
}, 500);
});
after(function (done) {
meta.config.loggerStatus = 0;
meta.config.loggerIOStatus = 0;
done();
});
});
});

@ -57,7 +57,7 @@ describe('Upload Controllers', function () {
var csrf_token; var csrf_token;
before(function (done) { before(function (done) {
helpers.loginUser('regular', 'zugzug', function (err, _jar, io, _csrf_token) { helpers.loginUser('regular', 'zugzug', function (err, _jar, _csrf_token) {
assert.ifError(err); assert.ifError(err);
jar = _jar; jar = _jar;
csrf_token = _csrf_token; csrf_token = _csrf_token;
@ -155,7 +155,7 @@ describe('Upload Controllers', function () {
var csrf_token; var csrf_token;
before(function (done) { before(function (done) {
helpers.loginUser('admin', 'barbar', function (err, _jar, io, _csrf_token) { helpers.loginUser('admin', 'barbar', function (err, _jar, _csrf_token) {
assert.ifError(err); assert.ifError(err);
jar = _jar; jar = _jar;
csrf_token = _csrf_token; csrf_token = _csrf_token;

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save