forked from roopeshsn/freshcomm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductController.test.js
97 lines (96 loc) · 2.29 KB
/
productController.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
96
97
const app = require('../backend/server')
const Product = require('../backend/models/productModel')
const chai = require('chai')
const chaiHttp = require('chai-http')
const expect = chai.expect
chai.use(chaiHttp)
chai.should()
describe('PRODUCT TESTS', () => {
beforeEach((done) => {
Product.deleteMany({}, (err) => {
done()
})
})
describe('/GET /api/products', () => {
it('Should return all products', (done) => {
chai
.request(app)
.get('/api/products')
.end((err, res) => {
res.should.have.a('object')
done()
})
})
})
describe('/ GET /api/products/:id', () => {
it('should return product by id', (done) => {
const id = 1
chai
.request(app)
.get(`/api/products${id}`)
.end((err, res) => {
res.should.have.a('object')
done()
})
})
})
describe('/ DELETE /api/products/:id', () => {
it('should return product by id', (done) => {
const id = 1
chai
.request(app)
.delete(`/api/products${id}`)
.end((err, res) => {
res.should.have.a('object')
done()
})
})
})
describe('/ POST /api/products/', () => {
it('should create a product', (done) => {
let products = new Product({
name: 'Banana',
price: 20,
mrp: 1,
user: 1,
imageSrc: 'jkdekde',
imageAlt: 'kdieduied',
category: 'kdidldil',
countInStock: 2,
description: 'Test sweet',
})
chai
.request(app)
.post('/api/products')
.send(products)
.end((err, res) => {
res.should.have.a('object')
done()
})
})
})
describe('/ PUT /api/products/:id', () => {
it('should update a product', (done) => {
let id = 1
let products = new Product({
name: 'orange',
price: 27,
mrp: 2,
user: 1,
imageSrc: 'jkdekdess',
imageAlt: 'kdieduiedcsxdsx',
category: 'kdidldilxs',
countInStock: 3,
description: 'Test sweeter',
})
chai
.request(app)
.put(`/api/products/${id}`)
.send(products)
.end((err, res) => {
res.should.have.a('object')
done()
})
})
})
})