-
Notifications
You must be signed in to change notification settings - Fork 0
/
automation_api_delete_user.js
206 lines (160 loc) · 7.66 KB
/
automation_api_delete_user.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
const request_url = require("supertest")("http://barru.pythonanywhere.com");
const assert = require("chai").expect;
let random_text = Math.random().toString(36).substring(7); //generate random text
let authorize_value = ""; //global authorization with empty value
describe("POST /register then /login to get a valid authorization value", function () {
it("Verify Success Register First", async function () {
const response = await request_url
.post("/register")
.send({ email: random_text + "@gmail.com", password: random_text, name: random_text });
});
it("Verify Success Login", async function () {
const response = await request_url
.post("/login")
.send({ email: random_text + "@gmail.com", password: random_text });
authorize_value = response.body.credentials.access_token; //update empty authorization with valid value
});
});
describe("POST /delete-user", function () {
it("Verify Failed Delete User without Authorization", async function () {
const response = await request_url
.del("/delete-user")
.send({ password: random_text});
assert(response.status).to.eql(500);
});
it("Verify Failed Delete User with Invalid Password", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: "sigantengnih"});
const isi_data = response.body;
assert(response.body.status).to.eql('FAILED_DELETE_PROFILE');
assert(response.body.message).to.eql('Gagal Hapus Akun');
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Empty String", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: ""});
const isi_data = response.body;
assert(response.body.status).to.eql('FAILED_DELETE_PROFILE');
assert(response.body.message).to.eql('Gagal Hapus Akun');
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Integer value", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: 1});
assert(response.status).to.eql(500);
});
it("Verify Failed Delete User with Max Character", async function () {
let max_pass = Array.from(Array(40), () => Math.floor(Math.random() * 36).toString(36)).join('');
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: max_pass});
const isi_data = response.body;
assert(response.body.status).to.eql('FAILED_DELETE_PROFILE');
assert(response.body.message).to.eql('Gagal Hapus Akun');
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Older Authorization", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: '5836a5287ae73353561d307b72fe908b54bffd0a3113b708144c764dd7f5fdk2' })
.send({ password: "sman60jakarta"});
const isi_data = response.body;
assert(response.body.data).to.eql("User's not found");
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Empty Authorization", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: '' })
.send({ password: "sman60jakarta"});
const isi_data = response.body;
assert(response.body.data).to.eql("User's not found");
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Bearer Authorization and valid value", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ name: "sman60jakarta"});
assert(response.status).to.eql(500);
});
it("Verify Failed Delete User with Bearer Authorization and valid value", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: 'Bearer ' + authorize_value })
.send({ password: "sman60jakarta"});
const isi_data = response.body;
assert(response.body.data).to.eql("User's not found");
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with Bearer Authorization and wrong value", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: 'Bearer ' + 'hahahaahhahahahahahahahahahahaa' })
.send({ password: "sman60jakarta"});
const isi_data = response.body;
assert(response.body.data).to.eql("User's not found");
assert(isi_data).to.include.keys("data", "message", "status");
});
it("Verify Failed Delete User with GET Request", async function () {
const response = await request_url
.get("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: random_text});
assert(response.status).to.eql(405);
});
it("Verify Failed Delete User with POST Request", async function () {
const response = await request_url
.post("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: random_text});
assert(response.status).to.eql(405);
});
it("Verify Failed Delete User with PATCH Request", async function () {
const response = await request_url
.patch("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: random_text});
assert(response.status).to.eql(405);
});
it("Verify Failed Delete User with empty body only dictionary", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({});
assert(response.status).to.eql(500);
});
it("Verify Failed Delete User with xx-www-form-urlencoded as Body", async function () {
const response = await request_url
.del("/delete-user")
.set('content-Type', 'application/x-www-form-urlencoded')
.set({ Authorization: authorize_value })
.send({ password: "sman60jakarta"});
assert(response.status).to.eql(500);
});
it("Verify Failed Delete User with xx-www-form-urlencoded as Body", async function () {
const response = await request_url
.del("/delete-user")
.type('form')
.set({ Authorization: authorize_value })
.send({ password: "sman60jakarta"});
assert(response.status).to.eql(500);
});
it("Verify Success Delete User", async function () {
const response = await request_url
.del("/delete-user")
.set({ Authorization: authorize_value })
.send({ password: random_text});
const isi_data = response.body;
assert(response.body.status).to.eql('SUCCESS_DELETE_PROFILE');
assert(response.body.message).to.eql('Berhasil Hapus User');
assert(isi_data).to.include.keys("data", "message", "status");
});
});