Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions __test__/product.test.js
Original file line number Diff line number Diff line change
@@ -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");
});
})
2 changes: 1 addition & 1 deletion __test__/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
})
Expand Down
Binary file modified data/auth.db3
Binary file not shown.
9 changes: 6 additions & 3 deletions products/products-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions products/products-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
})
})
Expand Down