Files
mtusi2026lab2/postman/lab2.postman_collection.json
2026-10-23 16:31:42 +03:00

212 lines
6.5 KiB
JSON

{
"info": {
"name": "MTUSI lab2 messenger",
"description": "Local stand at http://localhost:8080. Run the folder from top to bottom. The first request fills usernames. Passwords stay in collection variables and are the synthetic lab password.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"variable": [
{"key": "baseUrl", "value": "http://localhost:8080"},
{"key": "password", "value": "Example-only-not-a-real-secret-123"},
{"key": "aliceUsername", "value": ""},
{"key": "bobUsername", "value": ""},
{"key": "aliceId", "value": ""},
{"key": "bobId", "value": ""},
{"key": "token", "value": ""},
{"key": "chatId", "value": ""},
{"key": "cursor", "value": ""}
],
"item": [
{
"name": "01 health live",
"request": {"method": "GET", "header": [], "url": "{{baseUrl}}/health/live"}
},
{
"name": "02 health ready",
"request": {"method": "GET", "header": [], "url": "{{baseUrl}}/health/ready"}
},
{
"name": "03 register Alice",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"const stamp = Date.now().toString(36);",
"pm.collectionVariables.set('aliceUsername', ('alice_' + stamp).slice(0, 32));",
"pm.collectionVariables.set('bobUsername', ('bob_' + stamp).slice(0, 32));"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"const body = pm.response.json();",
"pm.collectionVariables.set('aliceId', body.id);"
]
}
}
],
"request": {
"method": "POST",
"header": [{"key": "Content-Type", "value": "application/json"}],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"{{aliceUsername}}\",\n \"display_name\": \"Алиса\",\n \"password\": \"{{password}}\"\n}"
},
"url": "{{baseUrl}}/api/v1/users"
}
},
{
"name": "04 register Bob",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": ["pm.collectionVariables.set('bobId', pm.response.json().id);"]
}
}
],
"request": {
"method": "POST",
"header": [{"key": "Content-Type", "value": "application/json"}],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"{{bobUsername}}\",\n \"display_name\": \"Боб\",\n \"password\": \"{{password}}\"\n}"
},
"url": "{{baseUrl}}/api/v1/users"
}
},
{
"name": "05 login Alice Basic",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": ["pm.collectionVariables.set('token', pm.response.json().token);"]
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{"key": "username", "value": "{{aliceUsername}}", "type": "string"},
{"key": "password", "value": "{{password}}", "type": "string"}
]
},
"method": "POST",
"header": [],
"url": "{{baseUrl}}/api/v1/auth/sessions"
}
},
{
"name": "06 me with Bearer",
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "GET",
"header": [],
"url": "{{baseUrl}}/api/v1/users/me"
}
},
{
"name": "07 me with only X-User-Id",
"request": {
"method": "GET",
"header": [{"key": "X-User-Id", "value": "{{aliceId}}"}],
"url": "{{baseUrl}}/api/v1/users/me"
}
},
{
"name": "08 wrong password",
"request": {
"auth": {
"type": "basic",
"basic": [
{"key": "username", "value": "{{aliceUsername}}", "type": "string"},
{"key": "password", "value": "wrong-password-value", "type": "string"}
]
},
"method": "POST",
"header": [],
"url": "{{baseUrl}}/api/v1/auth/sessions"
}
},
{
"name": "09 create chat",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": ["pm.collectionVariables.set('chatId', pm.response.json().id);"]
}
}
],
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "POST",
"header": [{"key": "Content-Type", "value": "application/json"}],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Проект по ВНП\",\n \"member_ids\": [\"{{aliceId}}\", \"{{bobId}}\"]\n}"
},
"url": "{{baseUrl}}/api/v1/chats"
}
},
{
"name": "10 send message",
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "POST",
"header": [{"key": "Content-Type", "value": "application/json"}],
"body": {"mode": "raw", "raw": "{\n \"text\": \"Привет, Боб!\"\n}"},
"url": "{{baseUrl}}/api/v1/chats/{{chatId}}/messages"
}
},
{
"name": "11 first history page",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"const cursor = pm.response.json().next_cursor;",
"if (cursor) pm.collectionVariables.set('cursor', cursor);"
]
}
}
],
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "GET",
"header": [],
"url": "{{baseUrl}}/api/v1/chats/{{chatId}}/messages?limit=50"
}
},
{
"name": "12 logout",
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "DELETE",
"header": [],
"url": "{{baseUrl}}/api/v1/auth/sessions/current"
}
},
{
"name": "13 me after logout",
"request": {
"auth": {"type": "bearer", "bearer": [{"key": "token", "value": "{{token}}", "type": "string"}]},
"method": "GET",
"header": [],
"url": "{{baseUrl}}/api/v1/users/me"
}
}
]
}