aboutsummaryrefslogtreecommitdiff
path: root/test/test.js
diff options
context:
space:
mode:
authorHumairAK <humair88@hotmail.com>2016-07-26 21:31:27 +0000
committerHumairAK <humair88@hotmail.com>2016-07-26 21:31:27 +0000
commit9f65445e7fcd5cc5d9d3183cb280b1ba13ac30b7 (patch)
treed7157289f7bb8c07da715fbbfad719fb56a8fc53 /test/test.js
parentfa98fa652f41a7c87fe76ab57448ab702e06c82c (diff)
more unit tests
Diffstat (limited to 'test/test.js')
-rw-r--r--test/test.js51
1 files changed, 46 insertions, 5 deletions
diff --git a/test/test.js b/test/test.js
index dd47d48..2105f02 100644
--- a/test/test.js
+++ b/test/test.js
@@ -8,8 +8,8 @@ var fs = require('fs');
// Database info, cross check with database docs to ensure these files either:
-// a) exist
-// b) do not exist
+// We test get requests here mostly as those are the core functions of the
+// website that do not alter the database.
var examPull = fs.readFileSync("test/data/exam.json");
var exams = (JSON.parse(examPull));
@@ -19,8 +19,6 @@ var users = (JSON.parse(usersPull));
chai.use(chaiHttp);
-var request = require('supertest');
-
/* Test simple routes that do not require database queries */
describe('Test Simple Route:', function () {
@@ -247,7 +245,7 @@ describe('Questions Search Route:', function(){
* query and not return an exam at all, whereas before we pass in a
* legitimate hashed format id. Here we pass just random letters.
*/
- it.only('Search questions for gibberish id', function testSlash(done) {
+ it('Search questions for gibberish id', function testSlash(done) {
chai.request(server)
.get('/questions/batman')
.end(function(err, res){
@@ -263,3 +261,46 @@ describe('Questions Search Route:', function(){
});
+/* Solutions listing for a particular exam question
+* Pre-condition: Assume existing exam in db has at least question 1*/
+describe('Solutions Route:', function(){
+ var server;
+ before(function () {
+ server = require('./test_server');
+ });
+ after(function () {
+ server.close();
+ });
+
+
+ it('Search solutions for an existing exam', function testSlash(done) {
+ var qID = 1; //Check the first question
+ var examID = exams.existing._id.$oid;
+ chai.request(server)
+ .get('/solutions/' + examID + '/' + qID)
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ // Check for expected url path
+ var path = res.res.req.path;
+ assert.equal(path, '/solutions/' + examID + '/' + qID);
+ done();
+ });
+ });
+
+ it.only('Search solutions for a non existing exam', function testSlash(done) {
+ var qID = 1; //Check the first question
+ var examID = exams.nonExisting._id.$oid;
+ chai.request(server)
+ .get('/solutions/' + examID + '/' + qID)
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ // Check for expected url path
+ var path = res.res.req.path;
+ assert.equal(path, '/solutions/' + examID + '/' + qID);
+ done();
+ });
+ });
+
+
+});
+