Xpresso - "Lunch" missing from test db

Hi all,

I’m having a small issue with the Xpresso capstone project for NodeSQLite.

I’ve written the “GET /api/menus/:menuId/menu-items” route handler but when I run the tests I get the following result:

GET /api/menus/:menuId/menu-items
GET /api/menus/1/menu-items 200 1.953 ms - 249
√ should return all menu items of an existing menu
GET /api/menus/3/menu-items 200 0.523 ms - 16
√ should return an empty array for existing menus with no menu items
GET /api/menus/2/menu-items 404 0.326 ms - 9
3) should return a status code of 200 for valid menus
GET /api/menus/999/menu-items 404 1.197 ms - 9
√ should return a status code of 404 for invalid menus

I’ve investigated the test db at ./test/test.sqlite and it appears that in the Menu table, it is only ever seeding the following:

|id| title |

1 Breakfast
3 Dinner

Which means that the 3rd test for that route will always fail. I’m not sure if this is due to something I have done during set-up or if it’s an issue with the exercise, but if anyone else has had a similar problem, I would be very glad to find a solution!

I have also checked the production db and it has properly seeded all three Menus.

I have checked the ./test/seed.js file and the query to populate the test Menu database is as follows:

function seedMenuDatabase(done) {
  db.serialize(function() {
    db.run('DROP TABLE IF EXISTS Menu');
    db.run('CREATE TABLE IF NOT EXISTS `Menu` ( ' +
               '`id` INTEGER NOT NULL, ' +
               '`title` TEXT NOT NULL, ' +
               'PRIMARY KEY(`id`) )');
    db.run("INSERT INTO Menu (id, title) VALUES (1, 'Breakfast')");
    db.run("INSERT INTO Menu (id, title) VALUES (2, 'Lunch')");
    db.run("INSERT INTO Menu (id, title) VALUES (3, 'Dinner')", done);

So there doesn’t appear to be any reason the “Lunch” record should be missing when I view it in DB browser.

If any more info is required, please let me know!

Thanks in advance!

I have solved my own issue!

Turns out the “Lunch” entry in the test db was getting deleted because I hadn’t modified my Menu DELETE route to check for existing Menu-items before deleting. Got a bit ahead of myself, but it’s all sorted now!