Skip to content

Commit

Permalink
Merge pull request #23 from CMU-313/US4_endorse_backend_tests
Browse files Browse the repository at this point in the history
US4: Created more comprehensive back-end testing for endorsement
  • Loading branch information
tanoctavius authored Oct 10, 2024
2 parents 9addcdb + 2a4701b commit a90a8dd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 21 additions & 0 deletions UserGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Front-end New Features
1. Added `Endorse Topic` in Topic Tools drop-down menu. Button is activated upon clicked, and the topic will get endorsed.
2. Added Unendorse Topic feature that can undo Endorse Topic action. Will appear and replace Endorse Topic for endorsed topics.
3. Endorsement actions are logged just like other actions, i.e., lock and pin.
4. Added Endorsed tag in topic list (displayed after clicking on a category) for endorsed topics.
5. Configured `topic.json` and `error.json` for correct rendering.

### Front-end New Testing
1. Ensures correct API calls and privileged users have access to this feature.
2. Rendering test is done by user testing. All new features won't trigger explicit errors.

### Back-end Features
1. Added API calls for `endorse` and `unendorse`
2. Configured API response format to include `endorse`
3. Configured routes for `endorse`

### Back-end Testing
1. Automated test suite is included in `./test/topic.js`, primarily testing features of endorsement.
(describe what the test cases are doing)
2. Successful API calls are necessary to pass the test case.
However, do note that API calls are tested in pre-written test file `./test/api.js` and no modifications are made to it.
Binary file modified dump.rdb
Binary file not shown.
24 changes: 23 additions & 1 deletion test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ describe('Topic\'s', () => {
description: 'Test category created by testing script',
}));

// Comment @YG
// I created another topic for endorse testing.
topicEndorseTest = {
userId: fooUid,
Expand Down Expand Up @@ -706,7 +705,30 @@ describe('Topic\'s', () => {
assert(!isLocked);
});

// Test Cases for Endorsement Logic
it('should endorse topic by another admin', async () => {
await apiTopics.endorse({ uid: adminUid }, { tids: [endorseTestTopic.tid], cid: categoryObj.cid });
const isEndorsed = await topics.isEndorsed(endorseTestTopic.tid);
assert(isEndorsed);
});

it('should unendorse topic by another admin', async () => {
await apiTopics.unendorse({ uid: adminUid }, { tids: [endorseTestTopic.tid], cid: categoryObj.cid });
const isEndorsed = await topics.isEndorsed(endorseTestTopic.tid);
assert(!isEndorsed);
});

// Only admin can endorse, and should raise error if regular user wants to endorse
it('only admin can endorse', async () => {
try {
// Test a regular user
await apiTopics.endorse({ uid: fooUid }, { tids: [newTopic.tid], cid: categoryObj.cid });
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:no-privileges]]');
}
});
// End of implementation

it('should pin topic', async () => {
await apiTopics.pin({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid });
Expand Down

0 comments on commit a90a8dd

Please sign in to comment.