Skip to content

Commit

Permalink
added 2 test cases for testing if topic correctly updates resolved st…
Browse files Browse the repository at this point in the history
…atus when flagging
  • Loading branch information
Ginka3 committed Feb 22, 2025
1 parent 89cab7a commit 8893116
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,24 @@ describe('topicsController.setResolved - Unit Test', () => {
assert(res.status.calledWith(400));
assert(res.json.calledWithMatch({ error: "Invalid request. 'resolved' must be a boolean." }));
});

it('should update the database with the correct resolved status', async () => {
req.body.resolved = true;
await topicsController.setResolved(req, res);

const resolvedStatus = await topics.getTopicField(req.params.tid, 'resolved');
assert.strictEqual(resolvedStatus, 'true');
});

it('should not update the resolved status if the topic does not exist', async () => {
req.params.tid = 999999; // Non-existent topic
req.body.resolved = true;
await topicsController.setResolved(req, res);

assert(res.status.calledWith(404));
assert(res.json.calledWithMatch({ error: 'Topic not found' }));
});

});

// Integration Tests Marking Question Resolved/Unresolved
Expand Down

0 comments on commit 8893116

Please sign in to comment.