diff --git a/__test__/product.test.js b/__test__/product.test.js new file mode 100644 index 0000000..753c67c --- /dev/null +++ b/__test__/product.test.js @@ -0,0 +1,25 @@ +const supertest = require('supertest') +const server = require('../api/server') +const db = require('../data/db-Config') + +describe('Products test', () => { + it('Products add sucessfully', async () => { + const res = await supertest(server).post('/api/products') + .send({ + name: 'orange', + description: 'Its orange', + market_location: 'trees', + quantity: '10', + price: '25', + user_id: 1 + }) + expect(res.status).toBe(200) + }) + + it("should return json", async () => { + const res = await supertest(server) + .post("/api/products") + .send({ name: "grapes", description: "theyre sweet", quantity: "35", price:"10", user_id: 1 }); + expect(res.type).toBe("application/json"); + }); +}) \ No newline at end of file diff --git a/__test__/user.test.js b/__test__/user.test.js index 2b79e35..158fdf4 100644 --- a/__test__/user.test.js +++ b/__test__/user.test.js @@ -14,7 +14,7 @@ describe('register', () => { it("register success", async () => { const res = await supertest(server).post('/api/auth/register') .send({ - username: 'john1', + username: 'john12', password: 'test', email: 'lambda4@testing.com' }) diff --git a/data/auth.db3 b/data/auth.db3 index 72a1fbd..ebb83b9 100644 Binary files a/data/auth.db3 and b/data/auth.db3 differ diff --git a/products/products-model.js b/products/products-model.js index 84a7246..69f3ab2 100644 --- a/products/products-model.js +++ b/products/products-model.js @@ -26,9 +26,12 @@ function find() { } function add(product) { - const [id] = db("products").insert(product, "id"); - - return findById(id); + return db("products") + .insert(product, "id") + .then(ids => { + const [id] = ids; + return findById(id); + }); } function findById(id) { diff --git a/products/products-router.js b/products/products-router.js index 2e23b70..8c17237 100644 --- a/products/products-router.js +++ b/products/products-router.js @@ -29,6 +29,7 @@ router.get('/', (req, res) => { res.status(200).json(product) }) .catch(err => { + console.log(err) res.status(500).json({ error: 'Something went wrong'}) }) })