Fixed indexing and added search test

master
Mark Moffat 2019-06-11 19:33:56 +09:30
parent 9208619803
commit 997d4d29c8
1 changed files with 13 additions and 3 deletions

View File

@ -16,7 +16,7 @@ let customers;
let users; let users;
let request = null; let request = null;
function setup(db){ function setup(db, app){
return Promise.all([ return Promise.all([
db.cart.remove({}, {}), db.cart.remove({}, {}),
db.users.remove({}, {}), db.users.remove({}, {}),
@ -29,7 +29,8 @@ function setup(db){
db.users.insertMany(jsonData.users), db.users.insertMany(jsonData.users),
db.customers.insertMany(jsonData.customers), db.customers.insertMany(jsonData.customers),
db.products.insertMany(common.fixProductDates(jsonData.products)), 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; config = app.config;
db = app.db; db = app.db;
await setup(db); await setup(db, app);
// Get some data from DB to use in compares // Get some data from DB to use in compares
products = await db.products.find({}).toArray(); 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); .expect(400);
t.deepEqual(res.body.message, 'Product not found in cart'); 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);
});