From 6cdb47ffd00ebfd63cdc05c91b95511490d851e1 Mon Sep 17 00:00:00 2001 From: Qasim Iqbal Date: Sun, 10 Apr 2016 21:36:10 -0400 Subject: [PATCH] Taking it as far as we can go with the code coverage --- src/api/courses/routes/filter.js | 7 ---- src/api/textbooks/routes/filter.js | 3 -- test/buildings/test.js | 28 ++++++++++++++ test/courses/test.js | 61 +++++++++++++++++++++++++++++- 4 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/api/courses/routes/filter.js b/src/api/courses/routes/filter.js index 0d92f6f..b43ba3c 100755 --- a/src/api/courses/routes/filter.js +++ b/src/api/courses/routes/filter.js @@ -86,10 +86,6 @@ export default function filter(req, res, next) { if(queries > 0) { if(isMapReduce) { - if(filter.$and.length === 0) { - filter = {} - } - var o = { query: filter, scope: { @@ -180,9 +176,6 @@ function formatPart(key, part) { part.value = part.value.substring(1, part.value.length - 1) } else { part.value = parseInt(part.value) - if (part.operator === '-') { - part.value = -part.value - } } if (['breadth', 'level', 'size', 'enrolment', 'start', 'end', 'duration'].indexOf(key) > -1) { diff --git a/src/api/textbooks/routes/filter.js b/src/api/textbooks/routes/filter.js index ec3f9fd..2cf4ff4 100755 --- a/src/api/textbooks/routes/filter.js +++ b/src/api/textbooks/routes/filter.js @@ -104,9 +104,6 @@ function formatPart(key, part) { part.value = part.value.substring(1, part.value.length - 1) } else { part.value = parseFloat(part.value) - if (part.operator === '-') { - part.value = -part.value - } } if (['edition', 'price'].indexOf(key) > -1) { diff --git a/test/buildings/test.js b/test/buildings/test.js index fddb37f..a8b6213 100755 --- a/test/buildings/test.js +++ b/test/buildings/test.js @@ -244,6 +244,34 @@ test.cb('/filter?q=lat:>=43%20AND%20lng:<=-79.1', t => { }) }) +test.cb('/filter?q=lat:>43%20AND%20lng:<-79.1', t => { + request(cobalt.Server) + .get('/1.0/buildings/filter?q=lat:>43%20AND%20lng:<-79.1') + .expect('Content-Type', /json/) + .expect(200) + .expect(JSON.stringify(testData.slice(0, 10))) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + +test.cb('/filter?q=lat:43.65963205070242%20AND%20lng:-79.3946933827686', t => { + request(cobalt.Server) + .get('/1.0/buildings/filter?q=lat:43.65963205070242%20AND%20lng:-79.3946933827686') + .expect('Content-Type', /json/) + .expect(200) + .expect(testData.filter(doc => { + return doc.id === '008A' + })) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + test.cb('/filter?q=campus:%22UTSG%22%20AND%20campus:-%22UTSG%22', t => { request(cobalt.Server) .get('/1.0/buildings/filter?q=campus:%22UTSG%22%20AND%20campus:-%22UTSG%22') diff --git a/test/courses/test.js b/test/courses/test.js index faaadcd..be74a75 100755 --- a/test/courses/test.js +++ b/test/courses/test.js @@ -255,11 +255,12 @@ test.cb('/filter?q=level:100%20OR%20name:%22econ%22', t => { test.cb('/filter?q=level:>=400%20AND%20department:-%22bio%22%20AND%20campus:%22UTSG%22', t => { request(cobalt.Server) - .get('/1.0/courses/filter?q=level:>300%20AND%20department:-%22bio%22%20AND%20campus:%22UTSG%22') + .get('/1.0/courses/filter?q=level:>=400%20AND%20department:-%22bio%22%20AND%20campus:%22UTSG%22') .expect('Content-Type', /json/) .expect(200) .expect(JSON.stringify(testData.filter(doc => { - return doc.code.includes('GGR498') || doc.code.includes('RSM429') || doc.code.includes('TRN421') + return doc.code.includes('GGR498') || doc.code.includes('RSM429') || + doc.code.includes('TRN421') }))) .end((err, res) => { if (err) t.fail(err.message) @@ -268,6 +269,35 @@ test.cb('/filter?q=level:>=400%20AND%20department:-%22bio%22%20AND%20campus:%22U }) }) +test.cb('/filter?q=level:<100', t => { + request(cobalt.Server) + .get('/1.0/courses/filter?q=level:<100') + .expect('Content-Type', /json/) + .expect(200) + .expect([]) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + +test.cb('/filter?q=breadth:<=1', t => { + request(cobalt.Server) + .get('/1.0/courses/filter?q=breadth:<=1') + .expect('Content-Type', /json/) + .expect(200) + .expect(testData.filter(doc => { + return doc.code.includes('EAS386') || doc.code.includes('MGR301') || + doc.code.includes('MHB256') + })) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + test.cb('/filter?q=size:15', t => { request(cobalt.Server) .get('/1.0/courses/filter?q=size:15') @@ -280,6 +310,33 @@ test.cb('/filter?q=size:15', t => { }) }) +test.cb('/filter?q=size:>5000', t => { + request(cobalt.Server) + .get('/1.0/courses/filter?q=size:>5000') + .expect('Content-Type', /json/) + .expect(200) + .expect(res => { + res.body[0].code = 'SOC102H1S' + }) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + +test.cb('/filter?q=instructor:-"D Liu"', t => { + request(cobalt.Server) + .get('/1.0/courses/filter?q=instructor:-"D Liu"') + .expect('Content-Type', /json/) + .expect(200) + .end((err, res) => { + if (err) t.fail(err.message) + t.pass() + t.end() + }) +}) + test.cb('/filter?q=instructor:%22Brown%22', t => { request(cobalt.Server) .get('/1.0/courses/filter?q=instructor:%22Brown%22')