-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl_notes_part2
282 lines (158 loc) · 9.69 KB
/
curl_notes_part2
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
Scenario 1. Use can change status archived - not archived using users#update endpoint
1. sign up
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
2. authenticate and get BR tocket
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/authentications --data \
'{"authentication": {"email": "[email protected]", "password": "welcome"}}'
Downloads/new_tesk_task_folder/staffomatic_user_management/staffomatic_user_management$ curl --request POST --header "Content-Type: application/json" \
> http://localhost:3189/authentications --data \
> '{"authentication": {"email": "[email protected]", "password": "welcome"}}'
{"user_id":1,"user_email":"[email protected]","token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE"}
3. create few more people
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
4.test if user can update state of himself
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X PUT -d '{"user":{"email":"[email protected]","is_archived":"true"}}' \
http://localhost:3189/users/1
5. test if user can update somebody else
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X PUT -d '{"user":{"email":"[email protected]","is_archived":"false"}}' \
http://localhost:3189/users/2
Scenario 2. Use can delete other users using users#destroy endpoint
1.Create few users
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
2.Delete one of the users
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X DELETE http://localhost:3189/users/5
3.User tries to delete himself
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X DELETE http://localhost:3189/users/1
3. Module Authenticatabale check
delete user
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X DELETE http://localhost:3189/users/7
change status of another user
create one user
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
update his is_archived status
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X PUT -d '{"user":{"email":"[email protected]","is_archived":"true"}}' \
http://localhost:3189/users/8
4. index endpoint
create 4 users with is_archived true
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
[4] pry(#<SignupsController>)> a.each do |b|
[4] pry(#<SignupsController>)* b.is_archived = true
[4] pry(#<SignupsController>)* b.save
[4] pry(#<SignupsController>)* end
create 3 users with is_archived false
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
index curl
for is_archvied:true records:
curl -X GET \
-H "Content-type: application/json" \
-H "Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
-d '{"filter": {"is_archived": "true"}}' \
"http://localhost:3189/users"
for is_archived:false recrods
curl -X GET \
-H "Content-type: application/json" \
-H "Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
-d '{"filter": {"is_archived": "false"}}' \
"http://localhost:3189/users"
5. log operation in update and destroy servcies
checking destroy endpoint
create new user
curl --request POST --header "Content-Type: application/json" \
http://localhost:3189/signup --data \
'{"data": {"attributes": {"email": "[email protected]", "password": "welcome", "password_confirmation": "welcome"}}}'
destroy user
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X DELETE http://localhost:3189/users/16
[1] pry(#<Services::Users::Destroy>)>
TRANSACTION (0.2ms) BEGIN
↳ app/services/users/destroy.rb:23:in `block in call'
User Destroy (0.3ms) DELETE FROM `users` WHERE `users`.`id` = 16
↳ app/services/users/destroy.rb:23:in `block in call'
Operation Create (0.4ms) INSERT INTO `operations` (`action`, `user`, `created_at`, `updated_at`) VALUES ('Destroy user', '#<User:0x00007f0b75cbd8b0>', '2022-09-13 23:05:14.407464', '2022-09-13 23:05:14.407464')
↳ app/services/users/destroy.rb:24:in `block in call'
TRANSACTION (19.2ms) COMMIT
↳ app/services/users/destroy.rb:21:in `call'
Completed 200 OK in 7092ms (Views: 0.2ms | ActiveRecord: 22.3ms | Allocations: 28770)
checking update endpoint
change status to is_archive:false for one user
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X PUT -d '{"user":{"email":"[email protected]","is_archived":"false"}}' \
http://localhost:3189/users/15
TRANSACTION (0.6ms) BEGIN
↳ app/services/users/update.rb:22:in `block in call'
User Exists? (0.9ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = '[email protected]' AND `users`.`id` != 15 LIMIT 1
↳ app/services/users/update.rb:22:in `block in call'
User Update (0.8ms) UPDATE `users` SET `users`.`updated_at` = '2022-09-13 23:08:05.718687', `users`.`is_archived` = FALSE WHERE `users`.`id` = 15
↳ app/services/users/update.rb:22:in `block in call'
Operation Create (0.4ms) INSERT INTO `operations` (`action`, `user`, `created_at`, `updated_at`) VALUES ('Update existing user', '#<User:0x00007f0b71c598a0>', '2022-09-13 23:08:05.748438', '2022-09-13 23:08:05.748438')
↳ app/services/users/update.rb:23:in `block in call'
TRANSACTION (43.7ms) COMMIT
6. send email testing
change status to is_archive:false for one user
curl --header \
"Authentication: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.JC6qKuH9SG0SIiYSfhZUFTtirxN9Q47buLk0DPFFFzE" \
--header "Content-Type: application/json" \
-X PUT -d '{"user":{"email":"[email protected]","is_archived":"false"}}' \
http://localhost:3189/users/15