HELP: Quality Assurance Projects - Issue Tracker

Tell us what’s happening:
Can’t pass all tests at the same time, some tests pass every now and then, not sure why.

Your code so far

/*
*
*
*       Complete the API routing below
*
*
*/

'use strict';

var expect = require('chai').expect;
let mongodb = require('mongodb')
let mongoose = require('mongoose')

let uri = process.env.PW

module.exports = function (app) {
  
  mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })
  
  let issueSchema = new mongoose.Schema({
    issue_title: {type: String, required: true},
    issue_text: {type: String, required: true},
    created_by : {type: String, required: true},
    assigned_to : String,
    status_text : String,
    open: {type: Boolean, required: true},
    created_on: {type: Date, required: true},
    updated_on: {type: Date, required: true},
    project: String
  })
  
  let Issue = mongoose.model('Issue', issueSchema)

  app.route('/api/issues/:project')
  
    .get(function (req, res){
      var project = req.params.project;
      let filterObject = Object.assign(req.query)
      filterObject['project'] =project
      Issue.find(
        filterObject,
        (error, arrayOfResults) => {
          if(!error && arrayOfResults){
            return res.json(arrayOfResults)
          }
        }
      )
    })
    
    .post(function (req, res){
      var project = req.params.project;
      if(!req.body.issue_title || !req.body.issue_text || !req.body.created_by){
        return res.json({ error: 'required field(s) missing' })
      }
      let newIssue = new Issue({
        issue_title: req.body.issue_title,
        issue_text: req.body.issue_text,
        created_by: req.body.created_by,
        assigned_to: req.body.assigned_to || '',
        status_text: req.body.status_text || '',
        open: true,
        created_on: new Date().toUTCString(),
        updated_on: new Date().toUTCString(),
        project: project
      })
      newIssue.save((error, savedIssue) => {
        if(!error && savedIssue){
          return res.json(savedIssue)
        }
      })
      
    })
    
    .put(function (req, res){
      var project = req.params.project;
      let updateObject = {}
      Object.keys(req.body).forEach((key) => {
        if(req.body[key] != ''){
          updateObject[key] = req.body[key]
        }
      })
      if(Object.keys(updateObject).length < 2){
        return res.json({ error: 'missing _id' })
      }
      updateObject['updated_on'] = new Date().toUTCString()
      Issue.findByIdAndUpdate(
      req.body._id,
      updateObject,
      {new: true},
      (error, updatedIssue) => {
       if(!error && updatedIssue){
          return res.json({ result: 'successfully updated', '_id': req.body._id })
        }else if (!updatedIssue){
          return res.json({ error: 'no update field(s) sent', '_id': req.body._id })
        } else {
          return res.json({ error: 'could not update', '_id': req.body._id })
        }
      }
        )
    })
    
    .delete(function (req, res){
      var project = req.params.project;
      if(!req.body._id){
        return res.json({ error: 'missing _id' })
      }
      Issue.findByIdAndRemove(req.body._id, (error, deletedIssue) => {
        if(!error && deletedIssue){
          res.json({ result: 'successfully deleted', '_id': req.body._id })
        }else if(!deletedIssue){
          res.json({ error: 'could not delete', '_id': req.body._id })
        }
      })
    });
    
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Issue Tracker

Link to the challenge:

Please help, I’d be very grateful!

The only test that does not pass now is: When the PUT request sent to /api/issues/{projectname} does not include update fields, the return value is { error: 'no update field(s) sent', '_id': _id } . On any other error, the return value is { error: 'could not update', '_id': _id } .

Did I pass all tests? Is this an error or? It won’t let me complete it.

Hello there,

Would you mind sharing a link to your project code? We cannot help without more information.

Also, did you write the functional tests for the app?

2 Likes

Hello,

Thank you for your reply. The project can be accessed here: https://deciduous-enormous-bismuth.glitch.me

Many thanks for your help!

You do not seem to have written this test:

suite('DELETE /api/issues/{project}', function() {

    test('Valid _id', function(done) {
      
      done();
    });

Hi,
Thank you.
It’s in there (functional tests js - line 212). Any other ideas? Maybe it’s something else?

When I look at your code, it does not appear complete:
image

Also, I see your tests fail 5/14:
image

Look in the Glitch logs to correct the failing tests.

Thank you so much! Thank you so much!

Please help me out, I am also facing the issues to complete this project
My glitch link: https://glitch.com/edit/#!/issue-trackers-app