test: fix assert.reject calls

fix tests
isekai-main
Barış Soner Uşaklı 2 years ago
parent 048fbcaac0
commit e0db9a8978

@ -388,6 +388,9 @@ postsAPI.deleteDiff = async (caller, { pid, timestamp }) => {
};
postsAPI.getReplies = async (caller, { pid }) => {
if (!utils.isNumber(pid)) {
throw new Error('[[error:invalid-data]]');
}
const { uid } = caller;
const canRead = await privileges.posts.can('topics:read', pid, caller.uid);
if (!canRead) {

@ -279,11 +279,17 @@ topicsAPI.markRead = async (caller, { tid }) => {
};
topicsAPI.markUnread = async (caller, { tid }) => {
if (!tid || caller.uid <= 0) {
throw new Error('[[error:invalid-data]]');
}
await topics.markUnread(tid, caller.uid);
topics.pushUnreadCount(caller.uid);
};
topicsAPI.bump = async (caller, { tid }) => {
if (!tid) {
throw new Error('[[error:invalid-tid]]');
}
const isAdminOrMod = await privileges.topics.isAdminOrMod(tid, caller.uid);
if (!isAdminOrMod) {
throw new Error('[[error:no-privileges]]');

@ -737,7 +737,10 @@ describe('Groups', () => {
const uid1 = await User.create({ username: utils.generateUUID().slice(0, 8) });
const uid2 = await User.create({ username: utils.generateUUID().slice(0, 8) });
await assert.rejects(apiGroups.join({ uid: uid1 }, { slug: 'test', uid: uid2 }), { message: '[[error:not-allowed]]' });
await assert.rejects(
apiGroups.join({ uid: uid1 }, { slug: 'test', uid: uid2 }),
{ message: '[[error:not-allowed]]' }
);
});
it('should allow admins to join private groups', async () => {
@ -923,7 +926,10 @@ describe('Groups', () => {
});
it('should error if not owner or admin', async () => {
await assert.rejects(apiGroups.accept({ uid: 0 }, { slug: 'privatecanjoin', uid: testUid }), { message: '[[error:no-privileges]]' });
await assert.rejects(
apiGroups.accept({ uid: 0 }, { slug: 'privatecanjoin', uid: testUid }),
{ message: '[[error:no-privileges]]' }
);
});
it('should accept membership of user', async () => {
@ -950,7 +956,10 @@ describe('Groups', () => {
});
it('should error if user is not invited', async () => {
await assert.rejects(apiGroups.acceptInvite({ uid: adminUid }, { slug: 'privatecanjoin', uid: adminUid }), { message: '[[error:not-invited]]' });
await assert.rejects(
apiGroups.acceptInvite({ uid: adminUid }, { slug: 'privatecanjoin', uid: adminUid }),
{ message: '[[error:not-invited]]' }
);
});
it('should accept invite', async () => {
@ -982,7 +991,10 @@ describe('Groups', () => {
});
it('should fail to kick user with invalid data', async () => {
await assert.rejects(apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: 8721632 }), { message: '[[error:group-not-member]]' });
await assert.rejects(
apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: 8721632 }),
{ message: '[[error:group-not-member]]' }
);
});
it('should kick user from group', async () => {
@ -1194,7 +1206,10 @@ describe('Groups', () => {
});
it('should error if user is not member', async () => {
await assert.rejects(apiGroups.leave({ uid: adminUid }, { uid: 3, slug: 'newgroup' }), { message: '[[error:group-not-member]]' });
await assert.rejects(
apiGroups.leave({ uid: adminUid }, { uid: 3, slug: 'newgroup' }),
{ message: '[[error:group-not-member]]' }
);
});
it('should fail if trying to remove someone else from group', async () => {

@ -605,11 +605,10 @@ describe('Post\'s', () => {
it('should not delete first diff of a post', async () => {
const timestamps = await posts.diffs.list(replyPid);
await assert.rejects(async () => {
await posts.diffs.delete(replyPid, timestamps[0], voterUid);
}, {
message: '[[error:invalid-data]]',
});
await assert.rejects(
posts.diffs.delete(replyPid, timestamps[0], voterUid),
{ message: '[[error:invalid-data]]' }
);
});
it('should delete a post diff', async () => {

@ -287,33 +287,36 @@ describe('Topic\'s', () => {
});
it('should error if pid is not a number', async () => {
assert.rejects(apiPosts.getReplies({ uid: 0 }, { pid: 'abc' }, '[[error:invalid-data]]'));
await assert.rejects(
apiPosts.getReplies({ uid: 0 }, { pid: 'abc' }),
{ message: '[[error:invalid-data]]' }
);
});
it('should fail to create new reply with invalid user id', (done) => {
topics.reply({ uid: null, content: 'test post', tid: newTopic.tid }, (err) => {
assert.equal(err.message, '[[error:no-privileges]]');
assert.strictEqual(err.message, '[[error:no-privileges]]');
done();
});
});
it('should fail to create new reply with empty content', (done) => {
topics.reply({ uid: topic.userId, content: '', tid: newTopic.tid }, (err) => {
assert.ok(err);
assert.strictEqual(err.message, '[[error:content-too-short, 8]]');
done();
});
});
it('should fail to create new reply with invalid topic id', (done) => {
topics.reply({ uid: null, content: 'test post', tid: 99 }, (err) => {
assert.equal(err.message, '[[error:no-topic]]');
assert.strictEqual(err.message, '[[error:no-topic]]');
done();
});
});
it('should fail to create new reply with invalid toPid', (done) => {
topics.reply({ uid: topic.userId, content: 'test post', tid: newTopic.tid, toPid: '"onmouseover=alert(1);//' }, (err) => {
assert.equal(err.message, '[[error:invalid-pid]]');
assert.strictEqual(err.message, '[[error:invalid-pid]]');
done();
});
});
@ -1471,17 +1474,23 @@ describe('Topic\'s', () => {
});
it('should fail with invalid data', async () => {
assert.rejects(apiTopics.markUnread({ uid: adminUid }, null), '[[error:invalid-data]]');
await assert.rejects(
apiTopics.markUnread({ uid: adminUid }, { tid: null }),
{ message: '[[error:invalid-data]]' }
);
});
it('should fail if topic does not exist', async () => {
assert.rejects(apiTopics.markUnread({ uid: adminUid }, { tid: 1231082 }), '[[error:no-topic]]');
await assert.rejects(
apiTopics.markUnread({ uid: adminUid }, { tid: 1231082 }),
{ message: '[[error:no-topic]]' }
);
});
it('should mark topic unread', async () => {
await apiTopics.markUnread({ uid: adminUid }, { tid });
const hasRead = await topics.hasReadTopic(tid, adminUid);
assert.equal(hasRead, false);
assert.strictEqual(hasRead, false);
});
it('should fail with invalid data', (done) => {
@ -1556,15 +1565,24 @@ describe('Topic\'s', () => {
});
it('should fail with invalid data', async () => {
assert.rejects(apiTopics.bump({ uid: adminUid }, null, '[[error:invalid-tid]]'));
await assert.rejects(
apiTopics.bump({ uid: adminUid }, { tid: null }),
{ message: '[[error:invalid-tid]]' }
);
});
it('should fail with invalid data', async () => {
assert.rejects(apiTopics.bump({ uid: 0 }, { tid: [tid] }, '[[error:no-privileges]]'));
await assert.rejects(
apiTopics.bump({ uid: 0 }, { tid: [tid] }),
{ message: '[[error:no-privileges]]' }
);
});
it('should fail if user is not admin', async () => {
assert.rejects(apiTopics.bump({ uid: uid }, { tid }, '[[error:no-privileges]]'));
await assert.rejects(
apiTopics.bump({ uid: uid }, { tid }),
{ message: '[[error:no-privileges]]' }
);
});
it('should mark topic unread for everyone', async () => {

Loading…
Cancel
Save