cobalt-uoft / cobalt

Open data APIs for interfacing with public information from the University of Toronto.
https://cobalt.qas.im
MIT License
98 stars 20 forks source link

Bring code coverage up to 90% #35

Closed qasim closed 8 years ago

qasim commented 8 years ago

List of things not tested:

kashav commented 8 years ago

Started working on this, https://github.com/kshvmdn/cobalt/commit/77c218ac93559690b97d865cdbce1f4aebee5c0e. Coverage is up to 81%.

screen shot 2016-04-10 at 3 54 34 am

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?

qasim commented 8 years ago

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.

kashav commented 8 years ago

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"
qasim commented 8 years ago

Hmm, that's not good. We shouldn't have _id at all. I'll look into this and get back to you.