fix wrong error returns, more tests

v1.18.x
barisusakli 8 years ago
parent 5ceaf86c3d
commit d8a9df74d7

@ -107,7 +107,7 @@ module.exports = function (SocketPosts) {
SocketPosts.dismissFlag = function (socket, pid, callback) {
if (!pid || !socket.uid) {
return callback('[[error:invalid-data]]');
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
function (next) {
@ -138,7 +138,7 @@ module.exports = function (SocketPosts) {
SocketPosts.updateFlag = function (socket, data, callback) {
if (!data || !(data.pid && data.data)) {
return callback('[[error:invalid-data]]');
return callback(new Error('[[error:invalid-data]]'));
}
var payload = {};

@ -11,7 +11,7 @@ module.exports = function (SocketUser) {
SocketUser.changePicture = function (socket, data, callback) {
if (!socket.uid) {
return callback('[[error:invalid-uid]]');
return callback(new Error('[[error:invalid-uid]]'));
}
if (!data) {

@ -84,12 +84,13 @@ module.exports = function (SocketUser) {
}
SocketUser.changePassword = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:invalid-uid]]'));
}
if (!data || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
if (!socket.uid) {
return callback('[[error:invalid-uid]]');
}
user.changePassword(socket.uid, data, function (err) {
if (err) {
@ -108,7 +109,7 @@ module.exports = function (SocketUser) {
SocketUser.updateProfile = function (socket, data, callback) {
if (!socket.uid) {
return callback('[[error:invalid-uid]]');
return callback(new Error('[[error:invalid-uid]]'));
}
if (!data || !data.uid) {

@ -3,6 +3,8 @@
var request = require('request');
var nconf = require('nconf');
var myXhr = require('../mocks/newXhr');
var helpers = module.exports;
helpers.loginUser = function (username, password, callback) {
@ -11,8 +13,8 @@ helpers.loginUser = function (username, password, callback) {
url: nconf.get('url') + '/api/config',
json: true,
jar: jar
}, function (err, response, body) {
if (err || response.statusCode !== 200) {
}, function (err, res, body) {
if (err || res.statusCode !== 200) {
return callback(err || new Error('[[error:invalid-response]]'));
}
@ -26,11 +28,61 @@ helpers.loginUser = function (username, password, callback) {
headers: {
'x-csrf-token': body.csrf_token
}
}, function (err, response) {
if (err || response.statusCode !== 200) {
}, function (err, res) {
if (err || res.statusCode !== 200) {
return callback(err || new Error('[[error:invalid-response]]'));
}
callback(null, jar);
myXhr.callbacks.test2 = function () {
this.setDisableHeaderCheck(true);
var stdOpen = this.open;
this.open = function () {
stdOpen.apply(this, arguments);
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
};
};
var socketClient = require('socket.io-client');
var io = socketClient.connect(nconf.get('url'), {forceNew: true, multiplex: false});
io.on('connect', function () {
callback(null, jar, io);
});
io.on('error', function (err) {
callback(err);
});
});
});
};
helpers.initSocketIO = function (callback) {
var jar;
request.get({
url: nconf.get('url') + '/api/config',
jar: jar,
json: true
}, function (err, res, body) {
if (err) {
return callback(err);
}
myXhr.callbacks.test2 = function () {
this.setDisableHeaderCheck(true);
var stdOpen = this.open;
this.open = function () {
stdOpen.apply(this, arguments);
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
};
};
var io = require('socket.io-client')(nconf.get('url'), {forceNew: true});
io.on('connect', function () {
callback(null, jar, io);
});
io.on('error', function (err) {
callback(err);
});
});
};
};

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