Quality Assurance Projects - Issue Tracker

I don’t know what part of the code is showing mistake??
https://boilerplate-project-issuetracker.itty11.repl.co

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Quality Assurance Projects - Issue Tracker

Link to the challenge:

I forked your repl but it crashes immediately with this error:
Error: Cannot find module '../models/issues'

You have const Issue = require('../models/issues') at the top of your api file but /models/issues doesn’t exist.

Also, you have your MongoDB username and password on display publicly as you have it stored in a .env file. On replit, you should store environment variables (especially those containing sensitive information) in your Secrets tab, where they will not be publicly visible. Then delete your .env file altogether.

Once you have addressed both of these issues and you can get your repl running without crashing, we can see if there are other issues we can help with.

still not working…

const chaiHttp = require('chai-http');
const chai = require('chai');
const assert = chai.assert;
const server = require('../server');
const Issue = require('../models/issues');

chai.use(chaiHttp);

suite('Functional Tests', function() {

  suite('tests for route /api/issues/{project}', function() {

  const toCheck = {issue_title: 'my test', issue_text: 'text', created_by: 'Neeraj',assigned_to: 'someone', status_text: 'it is ok', open: true}
  
  test('#1 post with all fields', function(done) {
    chai.request(server)
    .post('/api/issues/my_test')
    .send(toCheck)
    .end(function(err, res) {
      assert.equal(res.status, 200)
      assert.equal(res.body.issue_title, toCheck.issue_title)
      assert.equal(res.body.issue_text, toCheck.issue_text)
      assert.equal(res.body.open, toCheck.open)
      assert.equal(res.body.status_text, toCheck.status_text)
      assert.equal(res.body.assigned_to, toCheck.assigned_to)
      assert.equal(res.body.created_by, toCheck.created_by)
      assert.isDefined(res.body._id)
    done()
    })
  })

  const secondTest = {issue_title: 'second test', issue_text: 'second one 12 more to go', created_by: 'neeraj'}
  
  test('#2 post with required fields only', 
    function(done) {
      chai.request(server)
      .post('/api/issues/second_test')
      .send(secondTest)
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.body.issue_title, secondTest.issue_title)
        assert.equal(res.body.issue_text, secondTest.issue_text)
        assert.equal(res.body.created_by, secondTest.created_by)
        assert.isDefined(res.body._id)
    done()
      })
    }
  )

  test('#3 post with missing required field', function(done) {
    chai.request(server)
    .post('/api/issues/third_test')
    .send({issue_title: 'third test', issue_text: '11 more to go'})
    .end(function(err, res) {
      assert.equal(res.status, 200)
      assert.equal(res.text, '{"error":"required field(s) missing"}')
    done()
    })
  })

  test('#4 get without any query valid project name', function(done) {
    chai.request(server)
    .get('/api/issues/my_test')
    .end(function(err, res) {
      assert.equal(res.status, 200)
      assert.typeOf(res.body, 'array')
    done()
    })
  })

    test('#5 get with one filter', function(done) {
      chai.request(server)
      .get('/api/issues/second_test?open=true')
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.typeOf(res.body, 'array')
      done()
      })
    })

    test('#6 get with multiple filters', function(done) {
      chai.request(server)
      .get('/api/issues/second_test?open=true&created_by=neeraj')
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.typeOf(res.body, 'array')
      done()
      })
    })

    test('#7 put request to update one field', function(done) {
      chai.request(server)
      .put('/api/issues/get_issues_test_310846')
      .send({_id: '6363b73a9fc11fa7dd8f4092', status_text: 'Is it Ok or Not?'})
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"result":"successfully updated","_id":"6363b73a9fc11fa7dd8f4092"}')
      done()
      })
    })

    test('#8 put request to update multiple field', function(done) {
      chai.request(server)
      .put('/api/issues/get_issues_test_310846')
      .send({_id: '6363b73a9fc11fa7dd8f4092', status_text: 'It\'s okay to be not ok', issue_title: 'new one'})
      .end(async function(err, res) {

        assert.equal(res.status, 200)
        assert.equal(res.text, '{"result":"successfully updated","_id":"6363b73a9fc11fa7dd8f4092"}')
      done()
      })
    })

    test('#9 put request to update with missing id', function(done) {
      chai.request(server)
      .put('/api/issues/my_test')
      .send({ status_text: 'It\'s okay to be not ok', open:false})
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"error":"missing _id"}')
      done()
      })
    })

    test('#10 put request with no fields to update', function(done) {
      chai.request(server)
      .put('/api/issues/my_test')
      .send({_id: '635a70761ce9e3acec79221e'})
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"error":"no update field(s) sent","_id":"635a70761ce9e3acec79221e"}')
      done()
      })
    })

    test('#11 put request with invalid id', function(done) {
      chai.request(server)
      .put('/api/issues/my_test')
      .send({_id: '635aafe5b248f6442551ffff', status_text: 'not ok'})
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"error":"could not update","_id":"635aafe5b248f6442551ffff"}')
      })
      done()
      
    })
    
    test('#12 delete request with valid id', function(done) {
        
      // const issue = Issue.findOne({project_name: 'second_test'})
      chai.request(server)
        .delete('/api/issues/second_test')
        .send({_id: '635aafe5b248f6442551766f'})
        .end(function(err, res) {
          assert.equal(res.status, 200)
          assert.isObject(res.body)  
        done()
        })
      })
    
        test('#13 delete request with invalid id', function(done) {
      chai.request(server)
      .delete('/api/issues/my_test')
      .send({_id: '635aafe5b248f6442551ffff'})
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"error":"could not delete","_id":"635aafe5b248f6442551ffff"}')
      done()
      })
    })

    test('#14 delete request with missing id', function(done) {
      chai.request(server)
      .delete('/api/issues/my_test')
      .end(function(err, res) {
        assert.equal(res.status, 200)
        assert.equal(res.text, '{"error":"missing _id"}')
      done()
      })
    })
      
    })



  
});

You’ve removed your .env file but your repl is still crashing immediately because of the first issue I mentioned.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Why do you have this line of code in your repl?
What do you think its purpose is?
Like I said, at the moment it’s crashing your repl because it’s pointing at something which doesn’t exist.
This also means that you can’t use Issue anywhere else in your code, because you haven’t defined it correctly.

  1. Why do you have two different DB connections?

  2. Did you read the error message in the console?

MongooseError: Model.findOne() no longer accepts a callback

https://mongoosejs.com/docs/migrating_to_7.html


Did you write this locally and transferred it to Replit?

I don’t see how you managed to write all that code using the wrong version of Mongoose and without a working DB connection.

Don’t take this the wrong way but I have to ask this, are you copying and pasting code you didn’t write?

I messed the code so much. Anyway I tired of this
I’m done
Thank you
I quit

Hey!
Coding can seem really frustrating sometimes and you’ll feel like quitting more often than not with a lot of questions.

If you’re having trouble solving a problem, for a bit and come back to the problem once you’re well rested. The freeCodeCamp community will be here to help you.

Don’t give up bro!!
I’ve faced lots of challenges but I always scale through…
DON"T GIVE UP!!!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.