aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/exam.json28
-rw-r--r--test/test.js51
2 files changed, 59 insertions, 20 deletions
diff --git a/test/data/exam.json b/test/data/exam.json
index 0504679..ac9c0dc 100644
--- a/test/data/exam.json
+++ b/test/data/exam.json
@@ -1,32 +1,30 @@
{
"existing" : {
"_id": {
- "$oid": "57917d4d2a73c0224fb6e763"
+ "$oid": "578a429640e1bf7e118a6b7b"
},
- "course_code": "CSC373",
- "year": "2016",
- "term": "Midterm",
- "type": "Winter",
+ "course_code": "CSC148",
+ "year": 2010,
+ "term": "fall",
+ "type": "midterm",
"instructors": [
- "Robert Dane"
+ "Faith Ellen",
+ "Tom F."
],
- "page_count": "20",
- "questions_count": "2",
+ "page_count": 20,
+ "questions_count": 2,
"questions_list": [
{
"q_id": 1,
- "question": "Question 1"
+ "question": "this is q1"
},
{
"q_id": 2,
- "question": "Question 2"
+ "question": "this is q2"
}
],
- "upload_date": "2005-06-10",
- "uploaded_by": [
- "humair",
- ""
- ]
+ "upload_date": "some date",
+ "uploaded_by": "some user name"
},
"nonExisting" : {
"_id": {
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();
+ });
+ });
+
+
+});
+