Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Taking it as far as we can go with the code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
qasim committed Apr 11, 2016
1 parent 2bb22b7 commit 6cdb47f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
7 changes: 0 additions & 7 deletions src/api/courses/routes/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/api/textbooks/routes/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions test/buildings/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
61 changes: 59 additions & 2 deletions test/courses/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 6cdb47f

Please sign in to comment.