Boss Machine Project - Testing

https://www.codecademy.com/paths/web-development/tracks/javascript-back-end-development/modules/express-cumulative-project/informationals/bapi-p4-boss-machine

I did the extra bonus Work . I did it differently than the solution, where I made a Work router. I changed the solution to look more like mine and the Work tested just fine. My version, even though they look identical now, doesn’t even get to the workRouter, it states pending for all work routes. I can’t figure out why. When I test work itself on the webpage its working perfectly, its just when i run test i get:

BONUS: /api/minions/:minionId/work routes
GET /api/minions/:minionId/work
- returns an array
- returns an array of all all work for the specified minion
- called with a non-numeric minion ID returns a 404 error
- called with an invalid ID minion returns…

… 43 passing (7s)
18 pending

api.js

const express = require('express');
const apiRouter = express.Router();
const minionRouter = require('./minions');
const ideasRouter = require('./ideas');
const meetingsRouter = require('./meetings');



apiRouter.use('/minions', minionRouter);
apiRouter.use('/ideas', ideasRouter);
apiRouter.use('/meetings', meetingsRouter);



module.exports = apiRouter;

minions.js

const express = require('express');
const minionRouter = express.Router();
const workRouter = require('./work');

const {
    getAllFromDatabase,
    getFromDatabaseById,
    addToDatabase,
    updateInstanceInDatabase,
    deleteFromDatabasebyId,
  } = require('./db');



minionRouter.use('/:minionId/work', workRouter);

minionRouter.param('minionId', (req, res, next, id) => {
    const minion = getFromDatabaseById('minions', id);
    if (minion) {
      req.minion = minion;
      next();
    } else {
      res.status(404).send();
    }
  });


minionRouter.get('/', (req, res, next)=>{
    let minionArray = getAllFromDatabase('minions');
    res.send(minionArray);
});

minionRouter.post('/', (req, res, next)=>{
    res.status(201).send(addToDatabase('minions', req.body));
});

minionRouter.get('/:minionId', (req, res, next)=>{
    const minionData =  req.minion;
    res.send(minionData);
});

minionRouter.put('/:minionId', (req, res, next)=>{
    const updatedData = updateInstanceInDatabase('minions', req.body);
    res.send(updatedData)
});

minionRouter.delete('/:minionId', (req, res, next)=>{
    const didItDelete = deleteFromDatabasebyId('minions', req.params.minionId);
    if(didItDelete){
        res.status(204).send();
    }else{
        res.status(404).send();
    }

});


module.exports = minionRouter;

work.js

const express = require('express');
const workRouter = express.Router({mergeParams :true});
const {
    getAllFromDatabase,
    getFromDatabaseById,
    addToDatabase,
    updateInstanceInDatabase,
    deleteFromDatabasebyId,
  } = require('./db')

  workRouter.use((req,res,next)=>{
      //console.log('Working')
      next();
  })

workRouter.param('workId', (req, res, next, id) => {
    const work= getFromDatabaseById('work', id);
    if (work) {
      req.work = work;
      next();
    } else {
      res.status(404).send();
    }
  });


workRouter.get('/', (req, res, next)=>{
    let minionWork = getAllFromDatabase('work').filter((singleWork)=>{
        return singleWork.minionId === req.params.minionId
    });
    res.send(minionWork);
});

workRouter.post('/', (req, res, next)=>{
    const newData = req.body
    newData.minionId = req.params.minionId
    const createWork = addToDatabase('work', newData)
    res.status(201).send(createWork);
});


workRouter.put('/:workId', (req, res, next)=>{
    const updatedData = updateInstanceInDatabase('work', req.body)
    res.send(updatedData)
});

workRouter.delete('/:workId', (req, res, next)=>{
    const didItDelete = deleteFromDatabasebyId('work', req.params.workId);
    if(didItDelete){
        res.status(204).send();
    }else{
        res.status(404).send();
    }
});


module.exports = workRouter;

I finally replaced my test.js with the solutions and it finally worked. I think something was wrong with my version of test.js in the “start” folder.