From 0d5a182e4ffc11a6df7cc885520e0ffb4da7edae Mon Sep 17 00:00:00 2001 From: DSeeLP <46624152+DSeeLP@users.noreply.github.com> Date: Sun, 16 Mar 2025 10:58:24 +0100 Subject: [PATCH] add integration tests for chats --- tests/integration/chats.hurl | 132 +++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tests/integration/chats.hurl diff --git a/tests/integration/chats.hurl b/tests/integration/chats.hurl new file mode 100644 index 0000000..e2ee6c4 --- /dev/null +++ b/tests/integration/chats.hurl @@ -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}}