-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-test.http
More file actions
390 lines (321 loc) · 10.4 KB
/
api-test.http
File metadata and controls
390 lines (321 loc) · 10.4 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
### Collaboration Platform API Testing
### Base URL: http://localhost:3000
### Health Check
GET http://localhost:3000/health
Content-Type: application/json
### Expected Response:
# {
# "status": "OK",
# "timestamp": "2024-01-15T12:30:45.123Z",
# "uptime": 3600.5,
# "checks": {
# "database": "healthy",
# "redis": "healthy"
# }
# }
###
### Register New User
POST http://localhost:3000/api/auth/register
Content-Type: application/json
{
"email": "n@mail.com",
"name": "n smith",
"password": "securepassword123"
}
### Expected Response (201 Created):
# {
# "user": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null,
# "provider": "local",
# "createdAt": "2024-01-15T10:30:00.000Z",
# "updatedAt": "2024-01-15T10:30:00.000Z"
# },
# "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
# "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# }
###
### Login with Email and Password
POST http://localhost:3000/api/auth/login
Content-Type: application/json
{
"email": "john.doe@example.com",
"password": "securepassword123"
}
### Expected Response (200 OK):
# {
# "user": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null,
# "provider": "local",
# "createdAt": "2024-01-15T10:30:00.000Z",
# "updatedAt": "2024-01-15T10:30:00.000Z"
# },
# "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
# "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# }
###
### Refresh Access Token
POST http://localhost:3000/api/auth/refresh
Content-Type: application/json
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI4MGQ1MjUwNC0xZjg0LTRmMWItYmU0OC04YWFlZjI4Y2YxNWIiLCJpYXQiOjE3NTQ5MzQ2MDIsImV4cCI6MTc1NTUzOTQwMn0.aZJonVX3LK9P0FBhZ7_3sKxsmCwa2jXMULzQUFRzQTM"
}
### Expected Response (200 OK):
# {
# "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
# "user": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null,
# "provider": "local",
# "createdAt": "2024-01-15T10:30:00.000Z",
# "updatedAt": "2024-01-15T10:30:00.000Z"
# }
# }
###
### Logout User
POST http://localhost:3000/api/auth/logout
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1NTBlODQwMC1lMjliLTQxZDQtYTcxNi00NDY2NTU0NDAwMDAiLCJpYXQiOjE3MDUzMTQ2MDAsImV4cCI6MTcwNTkxOTQwMH0.def456"
}
### Expected Response (200 OK):
# {
# "message": "Logged out successfully"
# }
###
### Google OAuth Initiation
GET http://localhost:3000/api/auth/google
### Expected Response (302 Redirect):
# Location: https://accounts.google.com/oauth/authorize?response_type=code&client_id=YOUR_GOOGLE_CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fgoogle%2Fcallback&scope=profile%20email
###
### GitHub OAuth Initiation
GET http://localhost:3000/api/auth/github
### Expected Response (302 Redirect):
# Location: https://github.com/login/oauth/authorize?response_type=code&client_id=YOUR_GITHUB_CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fgithub%2Fcallback&scope=user%3Aemail
###
### Create New Document
POST http://localhost:3000/api/documents
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI5MWE5ZWE5Ni1lZDg1LTRjM2UtOWVmYS0wMzJhNWZhMGFkYzQiLCJlbWFpbCI6InBhbmRhQG1haWwuY29tIiwiaWF0IjoxNzU0OTQyNjU0LCJleHAiOjE3NTQ5NDM1NTR9.0ZrApwiWh7pk2v5ThuNrhjFLrzvGlHm-0JlceBG-DPE
Content-Type: application/json
{
"title": "My Project Proposal",
"content": "This is the initial content of my document. It will be converted to Yjs format automatically."
}
### Expected Response (201 Created):
# {
# "id": "123e4567-e89b-12d3-a456-426614174000",
# "title": "My Project Proposal",
# "content": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==",
# "ownerId": "550e8400-e29b-41d4-a716-446655440000",
# "createdAt": "2024-01-15T10:35:00.000Z",
# "updatedAt": "2024-01-15T10:35:00.000Z",
# "owner": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null
# }
# }
###
### List User's Documents
GET http://localhost:3000/api/documents
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
### Expected Response (200 OK):
# [
# {
# "id": "123e4567-e89b-12d3-a456-426614174000",
# "title": "My Project Proposal",
# "content": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==",
# "ownerId": "550e8400-e29b-41d4-a716-446655440000",
# "createdAt": "2024-01-15T10:35:00.000Z",
# "updatedAt": "2024-01-15T10:35:00.000Z",
# "owner": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null
# }
# }
# ]
###
### Get Document by ID
GET http://localhost:3000/api/documents/123e4567-e89b-12d3-a456-426614174000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
### Expected Response (200 OK):
# {
# "id": "123e4567-e89b-12d3-a456-426614174000",
# "title": "My Project Proposal",
# "content": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==",
# "ownerId": "550e8400-e29b-41d4-a716-446655440000",
# "createdAt": "2024-01-15T10:35:00.000Z",
# "updatedAt": "2024-01-15T10:35:00.000Z",
# "owner": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null
# }
# }
###
### Update Document (Full Update)
PATCH http://localhost:3000/api/documents/123e4567-e89b-12d3-a456-426614174000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
{
"title": "Updated Project Proposal",
"content": "This is the updated content with new information and additional details."
}
### Expected Response (200 OK):
# {
# "id": "123e4567-e89b-12d3-a456-426614174000",
# "title": "Updated Project Proposal",
# "content": "dXBkYXRlZCBjb250ZW50IGVuY29kZWQgaW4gWWpzIGZvcm1hdCB3aXRoIG5ldyBpbmZvcm1hdGlvbg==",
# "ownerId": "550e8400-e29b-41d4-a716-446655440000",
# "createdAt": "2024-01-15T10:35:00.000Z",
# "updatedAt": "2024-01-15T12:15:00.000Z",
# "owner": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null
# }
# }
###
### Update Document (Partial Update - Title Only)
PUT http://localhost:3000/api/documents/123e4567-e89b-12d3-a456-426614174000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
{
"title": "Just Update Title"
}
### Expected Response (200 OK):
# {
# "id": "123e4567-e89b-12d3-a456-426614174000",
# "title": "Just Update Title",
# "content": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==",
# "ownerId": "550e8400-e29b-41d4-a716-446655440000",
# "createdAt": "2024-01-15T10:35:00.000Z",
# "updatedAt": "2024-01-15T12:20:00.000Z",
# "owner": {
# "id": "550e8400-e29b-41d4-a716-446655440000",
# "email": "john.doe@example.com",
# "name": "John Doe",
# "avatar": null
# }
# }
###
### Delete Document
DELETE http://localhost:3000/api/documents/123e4567-e89b-12d3-a456-426614174000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
### Expected Response (204 No Content):
# (Empty response body)
###
### Error Examples
### Validation Error (400 Bad Request)
POST http://localhost:3000/api/auth/register
Content-Type: application/json
{
"email": "invalid-email",
"name": "",
"password": "123"
}
### Expected Response (400 Bad Request):
# {
# "error": "Validation error",
# "details": [
# {
# "field": "email",
# "message": "Invalid email"
# },
# {
# "field": "name",
# "message": "String must contain at least 1 character(s)"
# },
# {
# "field": "password",
# "message": "String must contain at least 6 character(s)"
# }
# ]
# }
###
### Unauthorized Access (401)
GET http://localhost:3000/api/documents
### Expected Response (401 Unauthorized):
# {
# "error": "Access token required"
# }
###
### Invalid Token (401)
GET http://localhost:3000/api/documents
Authorization: Bearer invalid-token
### Expected Response (401 Unauthorized):
# {
# "error": "Invalid token"
# }
###
### Document Not Found (404)
GET http://localhost:3000/api/documents/non-existent-id
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
### Expected Response (404 Not Found):
# {
# "error": "Document not found"
# }
###
### User Already Exists (409)
POST http://localhost:3000/api/auth/register
Content-Type: application/json
{
"email": "existing@example.com",
"name": "Existing User",
"password": "password123"
}
### Expected Response (409 Conflict):
# {
# "error": "User already exists with this email"
# }
###
### Rate Limit Exceeded (429)
### (After making 100+ requests in a minute)
### Expected Response (429 Too Many Requests):
# {
# "error": "Too many requests from this IP, please try again later."
# }
###
### WebSocket Connection Example (JavaScript)
### Use this in your frontend or testing tool:
# const socket = io('http://localhost:3000', {
# auth: {
# token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
# }
# });
#
# // Join document room
# socket.emit('document:join', {
# documentId: '123e4567-e89b-12d3-a456-426614174000'
# });
#
# // Listen for document state
# socket.on('document:state', (data) => {
# console.log('Document state:', data);
# });
#
# // Send document edit
# socket.emit('document:edit', {
# documentId: '123e4567-e89b-12d3-a456-426614174000',
# update: 'base64-encoded-yjs-update'
# });
#
# // Update presence
# socket.emit('presence:update', {
# documentId: '123e4567-e89b-12d3-a456-426614174000',
# cursor: { x: 150, y: 200 },
# selection: { start: 10, end: 25 }
# });