Closed qasim closed 8 years ago
Started working on this, https://github.com/kshvmdn/cobalt/commit/77c218ac93559690b97d865cdbce1f4aebee5c0e. Coverage is up to 81%.
Running into some problems with courses/filter
when filtering for matched sections with that added matched_meeting_sections
list. Any idea how to deal with that?
You might be able to use a .expect()
call like this:
.expect(res => {
let expected = testData.filter(doc => {
return /* doc filter here */
})
expected.matched_meeting_sections = []
for (let i = 0; i < expected.meeting_sections.length, i++) {
let expectedSections = expected.meeting_sections[i].filter(m => {
return /* meeting section filter here */
})
if (expectedSections.length > 0) {
expected.matched_meeting_sections.push(expectedSections)
}
}
res.body = expected;
})
Haven't tested that though, so may need some tweaking. If it doesn't work at all because of ordering / some other obscure issue, you can hardcode the answer too since the test data will remain static.
So it turns out the problem was that each meeting_sections
and matched_meeting_sections
object had a unique _id
key. Neither your solution nor hardcoding worked cause of that.
I tried removing all _id
keys when formatting the response:
for(let doc of docs) {
for (let section of ['meeting_sections', 'matched_meeting_sections']) {
if (doc.value.hasOwnProperty(section)) {
for (let i = 0; i < doc.value[section].length; i++) {
delete doc.value[section][i]._id
for (let j = 0; j < doc.value[section][i].times.length; j++) {
delete doc.value[section][i].times[j]._id
}
}
}
}
if (doc.value.hasOwnProperty('__v')) {
delete doc.value.__v
}
delete doc.value._id
formattedDocs.push(doc.value)
}
Tests are running fine now, but coverage seems to be failing for every case that checks for a meeting_section
.
Test:
test.cb('/filter?q=size:15', t => {
request(cobalt.Server)
.get('/1.0/courses/filter?q=size:15')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
if (err) t.fail(err.message)
t.pass()
t.end()
})
})
Response:
courses › test › /filter?q=size:15
expected 200 "OK", got 500 "Internal Server Error"
Hmm, that's not good. We shouldn't have _id
at all. I'll look into this and get back to you.
List of things not tested:
skip
paramsort
param with length 1<
,>
,<=
,>=
,-
) for each filter endpointsrc/db/index.js
from coverage detection