mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 19:41:16 +01:00
Merge remote-tracking branch 'origin/master' into develop
This commit is contained in:
@@ -288,6 +288,15 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should load tag rss feed', function (done) {
|
||||
request(nconf.get('url') + '/tags/nodebb.rss', function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load stylesheet.css', function (done) {
|
||||
request(nconf.get('url') + '/stylesheet.css', function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
86
test/rewards.js
Normal file
86
test/rewards.js
Normal file
@@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
|
||||
var db = require('./mocks/databasemock');
|
||||
var meta = require('../src/meta');
|
||||
var User = require('../src/user');
|
||||
var Groups = require('../src/groups');
|
||||
|
||||
describe('rewards', function () {
|
||||
var adminUid;
|
||||
var bazUid;
|
||||
var herpUid;
|
||||
|
||||
before(function (done) {
|
||||
Groups.resetCache();
|
||||
// Create 3 users: 1 admin, 2 regular
|
||||
async.series([
|
||||
async.apply(User.create, { username: 'foo', password: 'barbar' }),
|
||||
async.apply(User.create, { username: 'baz', password: 'quuxquux' }),
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' })
|
||||
], function (err, uids) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
adminUid = uids[0];
|
||||
bazUid = uids[1];
|
||||
herpUid = uids[2];
|
||||
|
||||
async.series([
|
||||
function (next) {
|
||||
Groups.join('administrators', adminUid, done);
|
||||
},
|
||||
function (next) {
|
||||
Groups.join('rewardGroup', adminUid, done);
|
||||
}
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rewards create', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
var rewards = require('../src/rewards');
|
||||
it('it should save a reward', function (done) {
|
||||
var data = [
|
||||
{
|
||||
rewards: { groupname: 'Gamers' },
|
||||
condition: 'essentials/user.postcount',
|
||||
conditional: 'greaterthan',
|
||||
value: '10',
|
||||
rid: 'essentials/add-to-group',
|
||||
claimable: '1',
|
||||
id: '',
|
||||
disabled: false
|
||||
}
|
||||
];
|
||||
|
||||
socketAdmin.rewards.save({uid: adminUid}, data, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should check condition', function (done) {
|
||||
function method(next) {
|
||||
next(null, 1);
|
||||
}
|
||||
rewards.checkConditionAndRewardUser(adminUid, 'essentials/user.postcount', method, function (err, data) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
});
|
||||
@@ -135,5 +135,41 @@ describe('Utility Methods', function () {
|
||||
done();
|
||||
});
|
||||
|
||||
it('escape html', function (done) {
|
||||
var escaped = utils.escapeHTML('&<>');
|
||||
assert.equal(escaped, '&<>');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should escape regex chars', function (done) {
|
||||
var escaped = utils.escapeRegexChars('some text {}');
|
||||
assert.equal(escaped, 'some\\ text\\ \\{\\}');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should get hours array', function (done) {
|
||||
var currentHour = new Date().getHours();
|
||||
var hours = utils.getHoursArray();
|
||||
var index = hours.length - 1;
|
||||
for (var i = currentHour, ii = currentHour - 24; i > ii; i--) {
|
||||
var hour = i < 0 ? 24 + i : i;
|
||||
assert.equal(hours[index], hour + ':00');
|
||||
-- index;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it('should get days array', function (done) {
|
||||
var currentDay = new Date(Date.now()).getTime();
|
||||
var days = utils.getDaysArray();
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
var index = 0;
|
||||
for(var x = 29; x >= 0; x--) {
|
||||
var tmpDate = new Date(currentDay - (1000 * 60 * 60 * 24 * x));
|
||||
assert.equal(months[tmpDate.getMonth()] + ' ' + tmpDate.getDate(), days[index]);
|
||||
++ index;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user