Skip to content

Commit

Permalink
Merge pull request #27 from CMU-17313Q/tests-for-anonymous-feature-to…
Browse files Browse the repository at this point in the history
…pics

Added tests for anonymous feature
  • Loading branch information
sarrakhelifi-cmu authored Oct 12, 2024
2 parents 28026ec + 0e8acfd commit 29d2091
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 52 deletions.
Binary file added dump.rdb
Binary file not shown.
26 changes: 0 additions & 26 deletions node_modules/nodebb-plugin-composer-default/static/lib/composer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
"connect-multiparty": "2.2.0",
"connect-pg-simple": "9.0.1",
"connect-redis": "7.1.1",
"cookie-parser": "1.4.6",
"cookie-parser": "^1.4.7",
"cron": "3.1.7",
"cropperjs": "1.6.2",
"csrf-sync": "4.0.3",
"daemon": "1.1.0",
"diff": "5.2.0",
"esbuild": "0.21.2",
"express": "^4.21.0",
"express-session": "1.18.0",
"express-session": "^1.18.1",
"express-useragent": "1.0.15",
"fetch-cookie": "3.0.1",
"file-loader": "6.2.0",
Expand Down Expand Up @@ -132,7 +132,7 @@
"serve-favicon": "2.5.0",
"sharp": "0.32.6",
"sitemap": "7.1.1",
"socket.io": "4.7.5",
"socket.io": "^4.8.0",
"socket.io-client": "4.7.5",
"sortablejs": "1.15.2",
"spdx-license-list": "6.9.0",
Expand Down
55 changes: 53 additions & 2 deletions test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ describe('Topic\'s', () => {
jar: jar,
json: true,
});

assert.strictEqual(result.body.status.code, 'ok');
assert.strictEqual(result.body.response.title, 'just a title');
assert.strictEqual(result.body.response.user.username, '[[global:guest]]');
Expand All @@ -199,7 +198,59 @@ describe('Topic\'s', () => {
assert.strictEqual(replyResult.body.response.content, 'a reply by guest');
assert.strictEqual(replyResult.body.response.user.username, '[[global:guest]]');
});

before(async () => {
adminUid = await User.create({ username: 'adminUser', password: 'securePassword' });
fooUid = await User.create({ username: 'regularUser' });
await groups.join('administrators', adminUid);
const adminSession = await helpers.loginUser('adminUser', 'securePassword');
adminJar = adminSession.jar;
csrf_token = adminSession.csrf_token;
categoryObj = await categories.create({
name: 'Sample Category',
description: 'A category created specifically for testing purposes',
});
topic = {
userId: adminUid,
categoryId: categoryObj.cid,
title: 'Sample Topic Title',
content: 'Content for sample topic',
};
});
it('should successfully create a new topic as a non-anonymous user', (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, adminUid);
assert.strictEqual(result.topicData.user.username, 'adminUser');
assert.strictEqual(result.topicData.user.displayname, 'adminUser');
done();
});
});
it('should successfully create a new topic with anonymous posting enabled', (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;
// Check if the user is recognized as a guest
assert.strictEqual(result.topicData.uid, 0); // UID for anonymous posts can be 0
assert.strictEqual(result.topicData.user.username, '[[global:guest]]'); // Verify guest username
assert.strictEqual(result.topicData.user.displayname, '[[global:guest]]'); // Verify guest display name
done();
});
});
it('should post a topic/reply as guest with handle if guest group has privileges', async () => {
const categoryObj = await categories.create({
name: 'Test Category',
Expand Down

0 comments on commit 29d2091

Please sign in to comment.