You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/test/rewards.js

80 lines
1.7 KiB
JavaScript

8 years ago
'use strict';
const assert = require('assert');
const async = require('async');
8 years ago
const db = require('./mocks/databasemock');
const meta = require('../src/meta');
const User = require('../src/user');
const Groups = require('../src/groups');
8 years ago
describe('rewards', () => {
let adminUid;
let bazUid;
let herpUid;
8 years ago
before((done) => {
8 years ago
// Create 3 users: 1 admin, 2 regular
async.series([
async.apply(User.create, { username: 'foo' }),
async.apply(User.create, { username: 'baz' }),
async.apply(User.create, { username: 'herp' }),
], (err, uids) => {
8 years ago
if (err) {
return done(err);
}
adminUid = uids[0];
bazUid = uids[1];
herpUid = uids[2];
async.series([
function (next) {
Groups.join('administrators', adminUid, next);
8 years ago
},
function (next) {
Groups.join('rewardGroup', adminUid, next);
},
8 years ago
], done);
});
});
describe('rewards create', () => {
const socketAdmin = require('../src/socket.io/admin');
const rewards = require('../src/rewards');
it('it should save a reward', (done) => {
const data = [
8 years ago
{
rewards: { groupname: 'Gamers' },
condition: 'essentials/user.postcount',
conditional: 'greaterthan',
value: '10',
rid: 'essentials/add-to-group',
claimable: '1',
id: '',
disabled: false,
},
8 years ago
];
socketAdmin.rewards.save({ uid: adminUid }, data, (err) => {
8 years ago
assert.ifError(err);
done();
});
});
it('should check condition', (done) => {
8 years ago
function method(next) {
next(null, 1);
}
rewards.checkConditionAndRewardUser({
uid: adminUid,
condition: 'essentials/user.postcount',
method: method,
}, (err, data) => {
8 years ago
assert.ifError(err);
done();
});
});
});
});