-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.test.js
More file actions
98 lines (73 loc) · 2.8 KB
/
product.test.js
File metadata and controls
98 lines (73 loc) · 2.8 KB
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
98
const mongoose = require("mongoose");
const request = require("supertest");
const app = require("./app");
console.log("***************************** Testing Phase *****************************");
require("dotenv").config();
/* Connecting to the database before each test. */
beforeEach(async () => {
mongoose.connect(process.env.DB_LOCAL_URI,{
useNewUrlParser:true,
useUnifiedTopology:true,
})
.then(con =>{
console.log(`MongoDB Database connected with Host :${con.connection.host}`)
})
});
describe("GET /api/v1/products", () => {
it("should return all products", async () => {
const res = await request(app).get("/api/v1/products");
expect(res.statusCode).toBe(200);
expect(res.body.productsCount).toBeGreaterThan(0);
});
});
describe("GET /api/v1/product/:id", () => {
it("should return a product", async () => {
const res = await request(app).get("/api/v1/product/635d5437aa2f80660653f747");
expect(res.statusCode).toBe(200);
expect(res.body.product.name).toBe("fish tank");
});
});
describe("GET /api/v1/admin/orders", () => {
it("should return a product", async () => {
const res = await request(app).get("/api/v1/admin/orders");
expect(res.statusCode).toBe(200);
});
});
describe("GET /api/v1/admin/orders" ,()=>{
it("should return all orders", async () => {
const res = await request(app).get("/api/v1/admin/orders");
expect(res.statusCode).toBe(200);
});
})
describe("GET /api/v1/order/:id" ,()=>{
it("should return the specific mentioned order", async () => {
const res = await request(app).get("/api/v1/order/6390d925430f1faa111d28d8");
expect(res.body.success).toBe(true);
});
})
describe("GET /api/v1/admin/users" ,()=>{
it("should return all users registered", async () => {
const res = await request(app).get("/api/v1/admin/users");
expect(res.statusCode).toBe(200);
expect(res.body.success).toBe(true);
});
})
describe("GET /api/v1/admin/user/:id" ,()=>{
it("should return the specific user", async () => {
const res = await request(app).get("/api/v1/admin/user/643f91ea5dc7a472b59b547c");
expect(res.statusCode).toBe(200);
expect(res.body.user.name).toBe('Mohan');
});
})
describe("GET /api/v1/admin/user/:id" ,()=>{
it("should return the specific user", async () => {
const res = await request(app).get("/api/v1/admin/user/643f91ea5dc7a472b59b547c");
console.log(res.body.user);
expect(res.statusCode).toBe(200);
expect(res.body.user.name).toBe('Mohan');
});
})
// /* Closing database connection after each test. */
// afterEach(async () => {
// await mongoose.connection.close();
// });