mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2025-12-24 13:02:50 +01:00
add integration tests for chats
This commit is contained in:
parent
e4fab172f0
commit
0d5a182e4f
132
tests/integration/chats.hurl
Normal file
132
tests/integration/chats.hurl
Normal file
@ -0,0 +1,132 @@
|
||||
POST {{host}}/api/login
|
||||
{
|
||||
"name": "user1",
|
||||
"password": "this-is-a-password"
|
||||
}
|
||||
HTTP 200
|
||||
|
||||
[Captures]
|
||||
user1-token: jsonpath "$.token"
|
||||
|
||||
POST {{host}}/api/login
|
||||
{
|
||||
"name": "user2",
|
||||
"password": "this-is-a-password"
|
||||
}
|
||||
HTTP 200
|
||||
|
||||
[Captures]
|
||||
user2-token: jsonpath "$.token"
|
||||
|
||||
POST {{host}}/api/login
|
||||
{
|
||||
"name": "user3",
|
||||
"password": "this-is-a-password"
|
||||
}
|
||||
HTTP 200
|
||||
|
||||
[Captures]
|
||||
user3-token: jsonpath "$.token"
|
||||
|
||||
GET {{host}}/api/users/@me
|
||||
Authorization: Bearer {{user1-token}}
|
||||
HTTP 200
|
||||
[Captures]
|
||||
user1: jsonpath "$.id"
|
||||
|
||||
GET {{host}}/api/users/@me
|
||||
Authorization: Bearer {{user2-token}}
|
||||
HTTP 200
|
||||
[Captures]
|
||||
user2: jsonpath "$.id"
|
||||
|
||||
POST {{host}}/api/chats
|
||||
Authorization: Bearer {{user1-token}}
|
||||
{
|
||||
"user": "user2"
|
||||
}
|
||||
HTTP 200
|
||||
|
||||
[Captures]
|
||||
chat: jsonpath "$.id"
|
||||
|
||||
# Verify that other users can't access chat
|
||||
|
||||
GET {{host}}/api/chats?limit=50
|
||||
Authorization: Bearer {{user3-token}}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.pagination.limit" == 50
|
||||
jsonpath "$.pagination.offset" == 0
|
||||
jsonpath "$.pagination.total" == 0
|
||||
jsonpath "$.result" isCollection
|
||||
jsonpath "$.result" isEmpty
|
||||
|
||||
GET {{host}}/api/chats/{{chat}}
|
||||
Authorization: Bearer {{user3-token}}
|
||||
HTTP 403
|
||||
GET {{host}}/api/chats/{{chat}}/messages?limit=50
|
||||
Authorization: Bearer {{user3-token}}
|
||||
HTTP 403
|
||||
|
||||
# List chats for all users that participate
|
||||
|
||||
GET {{host}}/api/chats?limit=50
|
||||
Authorization: Bearer {{user1-token}}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.pagination.limit" == 50
|
||||
jsonpath "$.pagination.offset" == 0
|
||||
jsonpath "$.pagination.total" == 1
|
||||
jsonpath "$.result" isCollection
|
||||
jsonpath "$.result[0].id" == {{chat}}
|
||||
|
||||
GET {{host}}/api/chats?limit=50
|
||||
Authorization: Bearer {{user2-token}}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.pagination.limit" == 50
|
||||
jsonpath "$.pagination.offset" == 0
|
||||
jsonpath "$.pagination.total" == 1
|
||||
jsonpath "$.result" isCollection
|
||||
jsonpath "$.result[0].id" == {{chat}}
|
||||
|
||||
# Post messages
|
||||
|
||||
POST {{host}}/api/chats/{{chat}}/messages
|
||||
Authorization: Bearer {{user1-token}}
|
||||
{
|
||||
"text": "Hello World 1"
|
||||
}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.text" == "Hello World 1"
|
||||
jsonpath "$.sender" == {{user1}}
|
||||
jsonpath "$.extra" == null
|
||||
[Captures]
|
||||
message1: jsonpath "$.id"
|
||||
|
||||
POST {{host}}/api/chats/{{chat}}/messages
|
||||
Authorization: Bearer {{user2-token}}
|
||||
{
|
||||
"text": "Hello World 2"
|
||||
}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.text" == "Hello World 2"
|
||||
jsonpath "$.sender" == {{user2}}
|
||||
jsonpath "$.extra" == null
|
||||
[Captures]
|
||||
message2: jsonpath "$.id"
|
||||
|
||||
# Verify list messages endpoint
|
||||
|
||||
GET {{host}}/api/chats/{{chat}}/messages?limit=50
|
||||
Authorization: Bearer {{user1-token}}
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
jsonpath "$.pagination.limit" == 50
|
||||
jsonpath "$.pagination.offset" == 0
|
||||
jsonpath "$.result" isCollection
|
||||
jsonpath "$.result[0].id" == {{message2}}
|
||||
jsonpath "$.result[1].id" == {{message1}}
|
||||
Loading…
x
Reference in New Issue
Block a user