Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Forum-Website/unit tests/forum.spec.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
134 lines (119 sloc)
3.45 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const Forums = require('../modules/forum.js') | |
//const Accounts = require('../modules/user.js') | |
describe('Create Forums()', () => { | |
test('Create a forum', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const forum = { | |
forum_name: 'test forum', | |
forum_description: 'test description', | |
forum_message: 'test message', | |
forum_links: 'test links' | |
} | |
const userData = { user: 'Admin', id: 1 } | |
const data = await forums.registerForum(forum, userData) | |
expect(data).toEqual({ 'changes': 1, 'lastID': 1 }) | |
done() | |
}) | |
test('error with our forum name', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const forum = { | |
forum_name: '', | |
forum_description: 'test description', | |
forum_message: 'test message', | |
forum_links: 'test links' | |
} | |
const userData = { user: 'Admin', id: 1 } | |
await expect(forums.registerForum(forum, userData)) | |
.rejects.toEqual(Error('missing forum name')) | |
done() | |
}) | |
test('error with initial message', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const forum = { | |
forum_name: 'test forum', | |
forum_description: 'test description', | |
forum_message: '', | |
forum_links: 'test links' | |
} | |
const userData = { user: 'Admin', id: 1 } | |
await expect(forums.registerForum(forum, userData)) | |
.rejects.toEqual(Error('missing initial message')) | |
done() | |
}) | |
test('error with forum description', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const forum = { | |
forum_name: 'test forum', | |
forum_description: '', | |
forum_message: 'test message', | |
forum_links: 'test links' | |
} | |
const userData = { user: 'Admin', id: 1 } | |
await expect(forums.registerForum(forum, userData)) | |
.rejects.toEqual(Error('missing forum description')) | |
done() | |
}) | |
/*test('Get all the forums', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
/*const forum = { | |
forum_name: 'test forum', | |
forum_description: 'test description', | |
forum_message: 'test message', | |
forum_links: 'test links' | |
}; | |
const userData = { user: 'Admin', id: 1 }; | |
const data = await forums.loadForumsData() | |
expect(data).toEqual([]) | |
done() | |
})*/ | |
}) | |
describe('Load the Forums()', () => { | |
test('Get all the forums', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const register = await forums.loadForumsData() | |
expect(register).toEqual([]) | |
done() | |
}) | |
test('Load the selected forums', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const forum = { | |
forum_name: 'test forum', | |
forum_description: 'test description', | |
forum_message: 'test message', | |
forum_links: 'test links' | |
} | |
const userData = { user: 'Admin', id: 1 } | |
await forums.registerForum(forum, userData) | |
const data = await forums.loadForumData({ forum_id: 1 }) | |
delete data.created_time | |
delete data.created_date | |
const expRes = { | |
'forum_description': 'test description', | |
'forum_link': 'test links', | |
'forum_message': 'test message', | |
'forum_name': 'test forum', | |
'id': 1, | |
'profile': 'undefined', | |
'user_id': 1, | |
'user_name': 'Admin' } | |
expect(data).toEqual(expRes) | |
done() | |
}) | |
}) | |
describe('Search the forum()', () => { | |
test('Get the desired data from search', async done => { | |
expect.assertions(1) | |
const forums = await new Forums() | |
const data = await forums.searchForumsData('data') | |
expect(data).toEqual([]) | |
done() | |
}) | |
}) |