Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing files for createNewTag #36

Open
wants to merge 10 commits into
base: f24
Choose a base branch
from
36 changes: 36 additions & 0 deletions test/webserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const assert = require('assert');
const webserver = require('../src/webserver');
const topics = require('../src/topics/tags');
const db = require('../src/database');

// Automated test cases generated with the help of ChatGPT

describe('createNewTag', () => {
let originalCreateEmptyTag;

it('should add "Homework" and "Assignment" tags correctly to the database', async () => {
// Act: Run the createNewTag function to add default tags
await webserver.createNewTag();

// Assert: Check if the tags are added correctly to the database
const tags = await topics.getTags(0, -1);
assert.strictEqual(tags.includes('Homework'), true, '"Homework" tag should be in the database');
assert.strictEqual(tags.includes('Assignment'), true, '"Assignment" tag should be in the database');
});

it('should not add tags to invalid forum categories', async () => {
// Simulate a scenario where the function tries to add tags to an invalid forum category

// Assuming there's an invalid category check in the createNewTag function, expect no tags to be added in this case
await topics.deleteTags(['Homework', 'Assignment']); // Unsure why topics.deleteTags is not related from src/topics/tags.js

// Act: Run createNewTag with invalid forum categories (this would need to be simulated in the webserver function)
await topics.createNewTag({ forumCategory: 'InvalidCategory' });

// Assert: Check that no tags have been added
const tags = await topics.getTags(0, -1);
assert.strictEqual(tags.length, 0, 'No tags should be added for invalid forum categories');
});
});
Loading