chat controller test

v1.18.x
barisusakli 8 years ago
parent 21e9c98973
commit 0d90279463

@ -74,6 +74,7 @@
"worker" : false, // Web Workers "worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host "wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface "yui" : false, // Yahoo User Interface
"mocha": true,
// Legacy // Legacy
"nomen" : false, // true: Prohibit dangling `_` in variables "nomen" : false, // true: Prohibit dangling `_` in variables

@ -1,9 +0,0 @@
{
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
// Custom Globals
"globals" : {
"it": false,
"describe": false
}
}

@ -0,0 +1,36 @@
'use strict';
var request = require('request');
var nconf = require('nconf');
var helpers = module.exports;
helpers.loginUser = function (username, password, callback) {
var jar = request.jar();
request({
url: nconf.get('url') + '/api/config',
json: true,
jar: jar
}, function (err, response, body) {
if (err || response.statusCode !== 200) {
return callback(err || new Error('[[error:invalid-response]]'));
}
request.post(nconf.get('url') + '/login', {
form: {
username: username,
password: password,
},
json: true,
jar: jar,
headers: {
'x-csrf-token': body.csrf_token
}
}, function (err, response) {
if (err || response.statusCode !== 200) {
return callback(err || new Error('[[error:invalid-response]]'));
}
callback();
});
});
};

@ -2,13 +2,15 @@
/*global require, before, after*/ /*global require, before, after*/
var assert = require('assert'); var assert = require('assert');
var db = require('./mocks/databasemock');
var async = require('async'); var async = require('async');
var request = require('request');
var nconf = require('nconf');
var db = require('./mocks/databasemock');
var User = require('../src/user'); var User = require('../src/user');
var Groups = require('../src/groups'); var Groups = require('../src/groups');
var Messaging = require('../src/messaging'); var Messaging = require('../src/messaging');
describe('Messaging Library', function () { describe('Messaging Library', function () {
var testUids; var testUids;
var fooUid; var fooUid;
@ -127,6 +129,17 @@ describe('Messaging Library', function () {
}); });
}); });
describe('controller', function () {
it('should 404 for guest', function (done) {
request(nconf.get('url') + '/user/baz/chats', function (err, response) {
assert.ifError(err);
assert.equal(response.statusCode, 404);
done();
});
});
});
after(function (done) { after(function (done) {
db.emptydb(done); db.emptydb(done);
}); });

Loading…
Cancel
Save