-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.test.js
95 lines (85 loc) · 2.03 KB
/
routes.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const { prisma, app } = require('./index')
const supertest = require('supertest')
const request = supertest(app)
beforeAll((done) => {
done();
})
afterAll(async (done) => {
await prisma.$disconnect()
//run.close(done)
done()
})
const item1 = {
id: '9999',
product: 'Test Item',
product_category: 'Test Category',
qty: '30',
price: '27.99',
vendor: 'Test Vendor',
location: 'Test Location'
}
const item2 = {
id: '9999',
product: 'Test Item 2',
product_category: 'Test Category',
qty: '30.o',
price: '27.adj',
vendor: 'Test Vendor',
location: 'Test Location'
}
it("creates an item", async (done) => {
const response = await request
.post("/create")
.send(item1)
.expect(302)
done()
})
it("edits an item", async (done) => {
const response = await request
.post("/inventory")
.send(item1)
.expect(302)
done()
})
it("edits an item with wrong data", async () => {
const response = await request
.post("/inventory")
.send(item2)
.expect(400)
expect(response.body).toEqual({"error": "Wrong data entered"})
})
it("deletes an item", async (done) => {
const response = await request
.delete("/inventory")
.send({ id: item1.id })
.expect(200)
done()
})
it("deletes an that doesn't exist", async (done) => {
const response = await request
.delete("/inventory")
.send({ id: 1293841287342 })
.expect(400)
done()
})
// update: async (req, res) => {
// console.log(req.body)
// const qty = Number(req.body.qty)
// const price = Number(req.body.price)
// if(isNaN(qty) || isNaN(price)) {
// res.status(400).send({"error": "Wrong data entered"})
// } else {
// await inventoryModel.updateInventory({
// id: parseInt(req.body.id),
// product: req.body.product,
// product_category: req.body.product_category,
// qty: parseInt(req.body.qty),
// price: price,
// vendor: req.body.vendor,
// location: req.body.location
// })
// .then(() => {
// res.redirect('/inventory');
// })
// }
// },