From 997d4d29c82237c0bf63af7909e13a222dfaed96 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Tue, 11 Jun 2019 19:33:56 +0930 Subject: [PATCH] Fixed indexing and added search test --- test/test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/test.js b/test/test.js index 945ead3..39adc19 100644 --- a/test/test.js +++ b/test/test.js @@ -16,7 +16,7 @@ let customers; let users; let request = null; -function setup(db){ +function setup(db, app){ return Promise.all([ db.cart.remove({}, {}), db.users.remove({}, {}), @@ -29,7 +29,8 @@ function setup(db){ db.users.insertMany(jsonData.users), db.customers.insertMany(jsonData.customers), db.products.insertMany(common.fixProductDates(jsonData.products)), - db.menu.insertOne(jsonData.menu) + db.menu.insertOne(jsonData.menu), + common.runIndexing(app) ]); }); } @@ -44,7 +45,7 @@ test.before(async () => { config = app.config; db = app.db; - await setup(db); + await setup(db, app); // Get some data from DB to use in compares products = await db.products.find({}).toArray(); @@ -168,3 +169,12 @@ test.serial('[Fail] Try remove an item which is not in the cart', async t => { .expect(400); t.deepEqual(res.body.message, 'Product not found in cart'); }); + +test.serial('[Success] Search products', async t => { + const res = await request + .get('/category/backpack?json=true') + .expect(200); + + // Should be two backpack products + t.deepEqual(res.body.length, 2); +});