-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.test.js
136 lines (108 loc) · 3.97 KB
/
app.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const supertest = require("supertest");
const app = require("./app");
describe("Posts", () => {
describe("POST tests", () => {
it("POST /posts --> cadastra um post", async () => {
const response = await supertest(app).post("/posts").send({
title: "Teste",
content: "Teste",
category: "Teste",
});
expect(response.status).toBe(201);
expect(response.body).toHaveProperty("id");
});
});
describe("GET tests", () => {
it("GET /posts --> Array de posts", async () => {
const response = await supertest(app).get("/posts");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(1);
});
it("GET /posts/:id --> Post especifico por ID", async () => {
const response = await supertest(app).get("/posts/1");
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("id");
});
it("GET /posts/:id --> Array vazio se não encontrado", async () => {
const response = await supertest(app).get("/posts/2");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(0);
});
});
describe("UPDATE tests", () => {
it("UPDATE /posts/:id --> atualiza os dados de um post", async () => {
const response = await supertest(app).put("/posts/1").send({
title: "Teste",
content: "Teste",
category: "Teste",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("id");
});
});
describe("DELETE tests", () => {
it("DELETE /posts/:id --> exclui um post", async () => {
const response = await supertest(app).delete("/posts/1");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(0);
});
});
});
describe("Usuários", () => {
describe("POST tests", () => {
it("POST /users --> cadastra um usuário", async () => {
const response = await supertest(app).post("/users").send({
name: "Teste",
email: "[email protected]",
password: "123456",
});
expect(response.status).toBe(201);
expect(response.body).toHaveProperty("id");
});
});
describe("GET tests", () => {
it("GET /users --> Array de usuários", async () => {
const response = await supertest(app).get("/users");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(1);
});
it("GET /users/:email --> Usuário especifico por email", async () => {
const response = await supertest(app).get("/users/email@email");
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("email");
});
it("GET /users/:email --> Array vazio se não encontrado", async () => {
const response = await supertest(app).get("/users/email@naoexiste");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(0);
});
it("GET /users/:name --> Usuário especifico por nome", async () => {
const response = await supertest(app).get("/users/Teste");
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("name");
});
it("GET /users/:name --> Array vazio se não encontrado", async () => {
const response = await supertest(app).get("/users/naoexiste");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(0);
});
});
describe("UPDATE tests", () => {
it("UPDATE /users/:id --> atualiza os dados de um usuário", async () => {
const response = await supertest(app).put("/users/1").send({
name: "Teste",
email: "[email protected]",
password: "123456",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("id");
});
});
describe("DELETE tests", () => {
it("DELETE /users/:id --> Excluir um usuário", async () => {
const response = await supertest(app).delete("/users/1");
expect(response.status).toBe(200);
expect(response.body).toHaveLength(0);
});
});
});