X-Press Publishing project: Incomplete test results

Hi, codecademy community

I’m trying to solve the capstone proyect for BUILDING A PERSISTENT API and when I reach the part for creating routes for the issues, I notice I don’t get the tests for that part when running $ npm test. I’ve looked into the test file and there are in fact test for the issue route but still they don’t show up when i run the tests. Here’s the code for the issue route I’m trying to test:

describe('POST /api/series/:seriesId/issues', function() {
  let newIssue;

  beforeEach(function(done) {
    newIssue = {
      name: 'New Issue',
      issueNumber: 3,
      publicationDate: 'January 3, 1990',
      artistId: 1
    };

    seed.seedIssueDatabase(done);
  });

  it('should create a valid issue', function(done) {
    request(app)
        .post('/api/series/2/issues')
        .send({issue: newIssue})
        .then(function() {
          testDb.all('SELECT * FROM Issue', function(error, result) {
            if (error) {
              throw new Error(error);
            }
            const issue = result.find(issue => issue.name === newIssue.name);
            expect(issue).to.exist;
            expect(issue.id).to.exist;
            expect(issue.name).to.equal(newIssue.name);
            expect(issue.issue_number).to.equal(newIssue.issueNumber);
            expect(issue.publication_date).to.equal(newIssue.publicationDate);
            expect(issue.artist_id).to.equal(newIssue.artistId);
            expect(issue.series_id).to.equal(2);
            done()
          });
        }).catch(done);
  });

  it('should return a 201 status code after issue creation', function() {
    return request(app)
        .post('/api/series/2/issues')
        .send({issue: newIssue})
        .expect(201);
  });

  it('should return the newly-created issue after issue creation', function() {
    return request(app)
        .post('/api/series/2/issues')
        .send({issue: newIssue})
        .then(function(response) {
          const issue = response.body.issue;
          expect(issue).to.exist;
          expect(issue.id).to.exist;
          expect(issue.name).to.equal(newIssue.name);
          expect(issue.issue_number).to.equal(newIssue.issueNumber);
          expect(issue.publication_date).to.equal(newIssue.publicationDate);
          expect(issue.artist_id).to.equal(newIssue.artistId);
          expect(issue.series_id).to.equal(2);
        });
  });

  it('should return a 400 status code for invalid issues', function() {
    newIssue = {
      issueNumber: 3,
      publicationDate: 'January 3, 1990',
      artistId: 1
    };

    return request(app)
        .post('/api/series/2/issues')
        .send({issue: newIssue})
        .expect(400);
  });

  it('should return a 400 status code if an artist with the issue\'s artist ID doesn\'t exist', function() {
    newIssue = {
      issueNumber: 3,
      publicationDate: 'January 3, 1990',
      artistId: 999
    };

    return request(app)
        .post('/api/series/2/issues')
        .send({issue: newIssue})
        .expect(400);
  });
});

And here’s the complete result of the tests where the issues route only has two tests for the DELETE method. Note: there are test for the Issues table but not for the routes.

MBP:~ myName$ cd /Users/myName/Documents/Development/capstone-project-1-x-press-publishing 
MBP:capstone-project-1-x-press-publishing myName$ npm test

> x-press-publishing@1.0.0 test /Users/myName/Documents/Development/capstone-project-1-x-press-publishing
> mocha



Listenening on port 8081
  Artist Table
    ✓ should exist
    ✓ should have name, date_of_birth, biography, and is_currently_employed columns with appropriate data types
    ✓ should have a required name column
    ✓ should have a required date_of_birth column
    ✓ should have a required biography column
    ✓ is_currently_employed should default to 1

  Series Table
    ✓ should exist
    ✓ should have id, name, and description columns with appropriate data types
    ✓ should have a required name column
    ✓ should have a required description column

  Issue Table
    ✓ should exist
    ✓ should have id, name, issue_number, publication_date, artist_id, and series_id columns with appropriate data types
    ✓ should have a required name column
    ✓ should have a required name column
    ✓ should have a required issue_number column
    ✓ should have a required publication_date column
    ✓ should have a required artist_id column
    ✓ should have a required series_id column

  GET /api/artists
GET /api/artists 200 4.781 ms - 242
    ✓ should return all currently-employed artists
GET /api/artists 200 1.453 ms - 242
    ✓ should return a status code of 200

  GET /api/artists/:id
GET /api/artists/2 200 1.431 ms - 127
    ✓ should return the artist with the given ID
GET /api/artists/2 200 0.843 ms - 127
    ✓ should return a 200 status code for valid IDs
GET /api/artists/999 404 0.563 ms - 9
    ✓ should return a 404 status code for invalid IDs

  POST /api/artists
POST /api/artists/ 201 3.372 ms - 127
    ✓ should create a valid artist
POST /api/artists/ 201 1.649 ms - 127
    ✓ should return a 201 status code after artist creation
POST /api/artists/ 201 1.984 ms - 127
    ✓ should return the newly-created artist after artist creation
POST /api/artists/ 201 1.757 ms - 127
    ✓ should set new artists as currently-employed by default
POST /api/artists/ 400 0.221 ms - 11
    ✓ should return a 400 status code for invalid artists

  PUT /api/artists/:id
PUT /api/artists/1 200 2.964 ms - 135
    ✓ should update the artist with the given ID
PUT /api/artists/1 200 2.916 ms - 135
    ✓ should return a 200 status code after artist update
PUT /api/artists/1 200 2.269 ms - 135
    ✓ should return the updated artist after artist update
PUT /api/artists/1 400 0.808 ms - 11
    ✓ should return a 400 status code for invalid artist updates

  DELETE /api/artists/:id
DELETE /api/artists/1 200 4.210 ms - 122
    ✓ should set the artist with the given ID as not currently-employed
DELETE /api/artists/1 200 1.773 ms - 122
    ✓ should return a 200 status code after artist delete
DELETE /api/artists/1 200 1.861 ms - 122
    ✓ should return the deleted artist after artist delete

  GET /api/series
GET /api/series 200 1.596 ms - 192
    ✓ should return all series
GET /api/series 200 0.456 ms - 192
    ✓ should return a status code of 200

  GET /api/series/:id
GET /api/series/2 200 2.336 ms - 70
    ✓ should return the series with the given ID
GET /api/series/2 200 0.448 ms - 70
    ✓ should return a 200 status code for valid IDs
GET /api/series/999 404 0.395 ms - 9
    ✓ should return a 404 status code for invalid IDs

  POST /api/series
POST /api/series/ 201 2.924 ms - 71
    ✓ should create a valid series
POST /api/series/ 201 2.210 ms - 71
    ✓ should return a 201 status code after series creation
POST /api/series/ 201 1.702 ms - 71
    ✓ should return the newly-created series after series creation
POST /api/series/ 400 0.238 ms - 11
    ✓ should return a 400 status code for invalid series

  PUT /api/series/:id
PUT /api/series/1 200 2.530 ms - 79
    ✓ should update the series with the given ID
PUT /api/series/1 200 2.252 ms - 79
    ✓ should return a 200 status code after series update
PUT /api/series/1 200 2.415 ms - 79
    ✓ should return the updated series after series update
PUT /api/series/1 400 0.736 ms - 11
    ✓ should return a 400 status code for invalid series updates

  DELETE /api/series/:id
DELETE /api/series/1 404 1.935 ms - 154
    ✓ should remove the series with the specified ID from the database if that series has no related issues
    1) "before each" hook

  GET /api/series/:seriesId/issues
    2) "before each" hook for "should return all issues of an existing series"


  49 passing (1s)
  2 failing

  1) DELETE /api/series/:id "before each" hook for "should return all issues of an existing series":
     TypeError: Cannot read property 'call' of undefined
  

  2) DELETE /api/series/:id "before each" hook for "should return all issues of an existing series":
     TypeError: Cannot read property 'call' of undefined
  



npm ERR! Test failed.  See above for more details.

I hope someone can tell me if I’m doing something wrong or if the test have a bug of some kind. Thanks in advance!

EDIT:
I just ran one of the skipped tests using mocha’s GREP option and it did run it. It returned a timeout error. Could it be related to the reason it doesn’t show up with the rest of the tests?
Here’s the terminal output:

MBP:capstone-project-1-x-press-publishing myName$ npm test -- -g 'should create a valid issue'

> x-press-publishing@1.0.0 test /Users/myName/Documents/Development/capstone-project-1-x-press-publishing
> mocha "-g" "should create a valid issue"



Listenening on port 8081
  POST /api/series/:seriesId/issues
    1) should create a valid issue


  0 passing (2s)
  1 failing

  1) POST /api/series/:seriesId/issues should create a valid issue:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  



npm ERR! Test failed.  See above for more details.
3 Likes

Same problem here…

1 Like

Hi there!

I was getting the same error and managed to solve it by writing the DELETE /api/series/:seriesId route in series.js. It seems like the error at this route is affecting the GET /api/series/:seriesId/issues testing.

After finding out that the skipped tests using GREP option (as @blameitonjoe explained above) were passing for me, I tried to copy the DELETE route from the Solution Code into the series.js and that allowed me to run the tests normally. Hope this works for you too!

PS: @Codecademy please solve this asap, these last lessons are quite hard and frustrating already without these weird bugs happening!

12 Likes

I’m having this problem, too.

Running npm test – -g ‘should return all issues of an existing series’ results in a pass, but npm test results in:

 49 passing (4s)
  2 failing

  1) DELETE /api/series/:id "before each" hook for "should return all issues of an existing series":
     TypeError: Cannot read property 'call' of undefined
      at processImmediate (internal/timers.js:439:21)

  2) DELETE /api/series/:id "before each" hook for "should return all issues of an existing series":
     TypeError: Cannot read property 'call' of undefined
      at processImmediate (internal/timers.js:439:21)

Really annoying - especially as I’m paying for this!

6 Likes

i am having problem with npm test,none of the test are passing ,i have checked my code it is correct

same issue here, did you find some solution?

I am having the same problems and be honest it is not motivating at all not to be able to see any results on your work. Personally, I changed to an older version of Node as suggested and that got me through some of the issues but some tests were still not passing.
In the end I found all this messing around with different versions and all that simply too time consuming and completed the exercise without being able to fully test it.
I honestly agree with everyone here that Codecademy should pay more attention to issues like this and update where necessary (I have come across other similar issues on different projects on this platform). I understand that keeping up with all the software version changes all the time can be difficult but we’re paying to use this platform and should be able to complete projects that are up to date.

3 Likes

Honestly this is ridiculous. First the dependancies wouldn’t install properly because this project is from 2017 and now I can’t even complete the project because the final tests within the test suite wont work…clearly nothing has been done about this over several months, I think I’m going to try get in touch with Codecademy and direct them to this thread and others like it to try get some results (results being the project being updated and rid of issues).

3 Likes

I’ve found a quick workaround - if you comment out the DELETE Series tests in test.js it should then continue to the rest of the tests. You can then undo this when you need to test that section again.

6 Likes

I’m having a similar issue and at this point I’m just going to give up on the project until it’s fixed. I agree with other commenters that it’s ridiculous to be paying for these projects that are out of date.

Commenting out the Series Delete test worked for me too. Thanks.

X-Press Publishing project: Incomplete test results SOLVED

  1. To run the app, you’ll need to trash the Codecademy skeleton code. IMHO, Delete it completely.

  2. Then get the solution code and install it twice. A) once as is so you have a solution to view if you must, and B) the Second time but change the name. So, you have a copy to play around, code, and learn.
    For example, my files are named “Solution” and “Ricks” to tell them apart.
    The above instructions will give you a solution file and a base/skeleton file updated as of Sept 2020. Remember, the existing skeleton contains outdated node dependencies and will cause exercise 2 and 48 failures during npm testing.

  3. Finally, go into your “copy” (RICKS in my case) and remove the contents of the api file. You will rebuild them in this exercise
    api.js
    artist.js
    issues.js
    series.js

  4. remove the server.js file as well. You will be rebuilding this file in the exercise.

So as you can see, the lesson is about CRUD and all the Express related topics from the prior exercises.
Hence by rebuilding the API folder and contents (four files. i.e., api, artist, issues, series) as well as the server.js file
you get exposure and some repetition to CRUD coding for Express.

ALTERNATIVELY,
You can try to update the dependencies yourself. That is beyond the scope of this lesson. However, in real life, you would have to search for solutions, and some challenges in real life will be even more formidable. Notwithstanding, you should crawl before you walk. Thus, even if you update the dependencies yourself, exercise 48 may still be frustrating because the software will not bypass the DELETE /api/series/:id Test. So you will have to also go into your test.js file and comment out the DELETE test until you are ready to test for the DELETE /api/series/:id. If you are relatively new to coding, take my advice (crawl first), import the solution code, and remove the folder/files listed above. The Solution code will work. Just remember after step 47, skip to 52 & 53 and write the DELETE code, then go back to 48, and your test for getting/api/series/:seriesId/issues should run. It worked for me.

Dirty Little Secret,
You can compare your code in VSCode side by side and use the “compare” feature. Right click on any file (not folder) to “select for compare” and inspect your code next to the answer file (right click a second time on the answer file and click “Compare with selected”). VSCode will highlight the differences. You should rarely use this unless you are totally stuck. If you look at the solution frequently, it’s a sign IMHO, that you are not ready for real-world applications. Before you use this naughty trick, sleep on your work overnight or at least take a short break. This was the advice given to me, and it has helped me countless times. Your mind can play tricks on your eyes. If you say “I don’t see it” and “my code is perfect” and “The solution is exactly what I have,” your mind will tell your eyes to stop spotting the problem. Take a break and say, “when I get back, I’ll get one step closer and perhaps even find the solution,” and your mind will help you “see” with your eyes.

2 Likes

Did you make it through the project. See my workaround if not. I’ve posted it as a reply to the original post by blameitonjoe.


Best
Rick

Did you resolve your struggles with X-press Publishing project. If not I’ve written a response with a workaround.


Best
Rick

Hi everyone!

I do agree with a lot of commentors about the un-indated projects as I have had many of these issues myself! I dont know if its CodeCademys way of forcing us to research the issues and become more independent??

Although i dont believe the teachings are enough to prepare us for handling these errors! Teach us how to attack these problems before forcing us into these problems!

Anyways like a few above have mentioned – If you add your seriesRouter.delete() code at the bottom of your series.js file and then run npm test you will pass the relevant GET :seriesId/issues test!

If you need help writing the logic you can download the solution code in the syllabus.

Hope this works for you! Happy coding.