mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: add missing tests
This commit is contained in:
@@ -20,14 +20,14 @@ Digest.execute = async function (payload) {
|
|||||||
const digestsDisabled = meta.config.disableEmailSubscriptions === 1;
|
const digestsDisabled = meta.config.disableEmailSubscriptions === 1;
|
||||||
if (digestsDisabled) {
|
if (digestsDisabled) {
|
||||||
winston.info(`[user/jobs] Did not send digests (${payload.interval}) because subscription system is disabled.`);
|
winston.info(`[user/jobs] Did not send digests (${payload.interval}) because subscription system is disabled.`);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let { subscribers } = payload;
|
let { subscribers } = payload;
|
||||||
if (!subscribers) {
|
if (!subscribers) {
|
||||||
subscribers = await Digest.getSubscribers(payload.interval);
|
subscribers = await Digest.getSubscribers(payload.interval);
|
||||||
}
|
}
|
||||||
if (!subscribers.length) {
|
if (!subscribers.length) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
winston.info(`[user/jobs] Digest (${payload.interval}) scheduling completed (${subscribers.length} subscribers). Sending emails; this may take some time...`);
|
winston.info(`[user/jobs] Digest (${payload.interval}) scheduling completed (${subscribers.length} subscribers). Sending emails; this may take some time...`);
|
||||||
@@ -36,6 +36,7 @@ Digest.execute = async function (payload) {
|
|||||||
subscribers: subscribers,
|
subscribers: subscribers,
|
||||||
});
|
});
|
||||||
winston.info(`[user/jobs] Digest (${payload.interval}) complete.`);
|
winston.info(`[user/jobs] Digest (${payload.interval}) complete.`);
|
||||||
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.error(`[user/jobs] Could not send digests (${payload.interval})\n${err.stack}`);
|
winston.error(`[user/jobs] Could not send digests (${payload.interval})\n${err.stack}`);
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@@ -82,12 +82,15 @@ describe('Topic\'s', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get post count', (done) => {
|
it('should get post count', async () => {
|
||||||
socketTopics.postcount({ uid: adminUid }, topic.tid, (err, count) => {
|
const count = await socketTopics.postcount({ uid: adminUid }, topic.tid);
|
||||||
assert.ifError(err);
|
assert.strictEqual(count, 1);
|
||||||
assert.equal(count, 1);
|
});
|
||||||
done();
|
|
||||||
});
|
it('should get users postcount in topic', async () => {
|
||||||
|
assert.strictEqual(await socketTopics.getPostCountInTopic({ uid: 0 }, 0), 0);
|
||||||
|
assert.strictEqual(await socketTopics.getPostCountInTopic({ uid: adminUid }, 0), 0);
|
||||||
|
assert.strictEqual(await socketTopics.getPostCountInTopic({ uid: adminUid }, topic.tid), 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load topic', async () => {
|
it('should load topic', async () => {
|
||||||
@@ -2221,6 +2224,42 @@ describe('Topic\'s', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('next post index', () => {
|
||||||
|
it('should error with invalid data', async () => {
|
||||||
|
await assert.rejects(socketTopics.getMyNextPostIndex({ uid: 1 }, null), { message: '[[error:invalid-data]]' });
|
||||||
|
await assert.rejects(socketTopics.getMyNextPostIndex({ uid: 1 }, {}), { message: '[[error:invalid-data]]' });
|
||||||
|
await assert.rejects(socketTopics.getMyNextPostIndex({ uid: 1 }, { tid: 1 }), { message: '[[error:invalid-data]]' });
|
||||||
|
await assert.rejects(socketTopics.getMyNextPostIndex({ uid: 1 }, { tid: 1, index: 1 }), { message: '[[error:invalid-data]]' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 if user has no posts in topic', async () => {
|
||||||
|
const uid = await User.create({ username: 'indexposter' });
|
||||||
|
const t = await topics.post({ uid: uid, title: 'topic 1', content: 'content 1', cid: categoryObj.cid });
|
||||||
|
const index = await socketTopics.getMyNextPostIndex({ uid: adminUid }, { tid: t.topicData.tid, index: 1, sort: 'oldest_to_newest' });
|
||||||
|
assert.strictEqual(index, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get users next post index in topic', async () => {
|
||||||
|
const t = await topics.post({ uid: adminUid, title: 'topic 1', content: 'content 1', cid: categoryObj.cid });
|
||||||
|
await topics.reply({ uid: adminUid, content: 'reply 1 content', tid: t.topicData.tid });
|
||||||
|
await topics.reply({ uid: adminUid, content: 'reply 2 content', tid: t.topicData.tid });
|
||||||
|
const index = await socketTopics.getMyNextPostIndex({ uid: adminUid }, { tid: t.topicData.tid, index: 1, sort: 'oldest_to_newest' });
|
||||||
|
assert.strictEqual(index, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get users next post index in topic by wrapping around', async () => {
|
||||||
|
const cat = await categories.create({ name: 'tag category' });
|
||||||
|
const t = await topics.post({ uid: adminUid, title: 'topic 1', content: 'content 1', cid: cat.cid });
|
||||||
|
await topics.reply({ uid: adminUid, content: 'reply 1 content', tid: t.topicData.tid });
|
||||||
|
await topics.reply({ uid: adminUid, content: 'reply 2 content', tid: t.topicData.tid });
|
||||||
|
let index = await socketTopics.getMyNextPostIndex({ uid: adminUid }, { tid: t.topicData.tid, index: 2, sort: 'oldest_to_newest' });
|
||||||
|
assert.strictEqual(index, 2);
|
||||||
|
index = await socketTopics.getMyNextPostIndex({ uid: adminUid }, { tid: t.topicData.tid, index: 3, sort: 'oldest_to_newest' });
|
||||||
|
assert.strictEqual(index, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('teasers', () => {
|
describe('teasers', () => {
|
||||||
let topic1;
|
let topic1;
|
||||||
let topic2;
|
let topic2;
|
||||||
|
|||||||
13
test/user.js
13
test/user.js
@@ -1508,6 +1508,19 @@ describe('User', () => {
|
|||||||
assert.strictEqual(sent, 0);
|
assert.strictEqual(sent, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get users with single uid', async () => {
|
||||||
|
const res = await User.digest.getUsersInterval(1);
|
||||||
|
assert.strictEqual(res, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not send digests', async () => {
|
||||||
|
const oldValue = meta.config.disableEmailSubsriptions;
|
||||||
|
meta.config.disableEmailSubsriptions = 1;
|
||||||
|
const res = await User.digest.execute({});
|
||||||
|
assert.strictEqual(res, false);
|
||||||
|
meta.config.disableEmailSubsriptions = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
it('should not send digests', async () => {
|
it('should not send digests', async () => {
|
||||||
await User.digest.execute({ interval: 'month' });
|
await User.digest.execute({ interval: 'month' });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user