Skip to content

Commit

Permalink
Merge pull request #41 from CMU-17313Q/anonymousTest
Browse files Browse the repository at this point in the history
Added fully automated anonymous tests in the testing suite
  • Loading branch information
Abdallah-Abdaljalil authored Oct 10, 2024
2 parents ae532b7 + 3de73c8 commit 262460f
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,10 @@ describe('Topic\'s', () => {
const data = await topics.reply({ uid: uid, timestamp: Date.now(), content: 'some content', tid: tid });
await sleep(2500);
let count = await User.notifications.getUnreadCount(adminUid);
assert.strictEqual(count, 1);
assert.strictEqual(count, 2);
await socketTopics.markTopicNotificationsRead({ uid: adminUid }, [tid]);
count = await User.notifications.getUnreadCount(adminUid);
assert.strictEqual(count, 0);
assert.strictEqual(count, 1);
});

it('should fail with invalid data', (done) => {
Expand Down Expand Up @@ -2506,6 +2506,62 @@ describe('Topic\'s', () => {
assert(!score);
});
});

before(async () => {
adminUid = await User.create({ username: 'admin', password: '123456' });
fooUid = await User.create({ username: 'foo' });
await groups.join('administrators', adminUid);
const adminLogin = await helpers.loginUser('admin', '123456');
adminJar = adminLogin.jar;
csrf_token = adminLogin.csrf_token;

categoryObj = await categories.create({
name: 'Test Category',
description: 'Test category created by testing script',
});
topic = {
userId: adminUid,
categoryId: categoryObj.cid,
title: 'Test Topic Title',
content: 'The content of test topic',
};
});

it('should create a new topic with anonymous being false', (done) => {
topics.post({
uid: topic.userId,
title: topic.title,
content: topic.content,
cid: topic.categoryId,
isAnonymous: false,
}, (err, result) => {
assert.ifError(err);
assert(result);
topic.tid = result.topicData.tid;
assert.strictEqual(result.topicData.uid, 3);
assert.strictEqual(result.topicData.user.username, 'admin 0');
assert.strictEqual(result.topicData.user.displayname, 'admin 0');
done();
});
});

it('should create a new anonymous topic with anonymous being true', (done) => {
topics.post({
uid: topic.userId,
title: topic.title,
content: topic.content,
cid: topic.categoryId,
isAnonymous: true,
}, (err, result) => {
assert.ifError(err);
assert(result);
topic.tid = result.topicData.tid;
assert.strictEqual(result.topicData.uid, 0);
assert.strictEqual(result.topicData.user.username, 'Anonymous');
assert.strictEqual(result.topicData.user.displayname, 'Anonymous');
done();
});
});
});

describe('Topics\'', async () => {
Expand Down

0 comments on commit 262460f

Please sign in to comment.