test: authenticate student tests with session tokens

This commit is contained in:
kk10
2026-10-05 13:42:00 +03:00
parent 385a8c0312
commit 79036b0f18
3 changed files with 45 additions and 26 deletions
+5 -6
View File
@@ -9,13 +9,11 @@ import (
"strconv"
"testing"
"github.com/google/uuid"
"mtusi2026-messenger/internal/dto"
)
func TestInvalidJSON(t *testing.T) {
resp := doRequest(t, http.MethodPost, "/api/v1/users", uuid.Nil, []byte(`{"username": "broken",`))
resp := doRequest(t, http.MethodPost, "/api/v1/users", "", []byte(`{"username": "broken",`))
requireStatus(t, resp, http.StatusBadRequest)
var apiErr dto.ErrorResponse
@@ -33,7 +31,7 @@ func TestForeignChat(t *testing.T) {
chat := createChat(t, user1, user1.ID, user2.ID)
resp := doRequest(t, http.MethodGet, "/api/v1/chats/"+chat.ID.String(), user3.ID, nil)
resp := doRequest(t, http.MethodGet, "/api/v1/chats/"+chat.ID.String(), user3.Token, nil)
requireStatus(t, resp, http.StatusNotFound)
resp = sendMessage(t, user3, chat.ID, "should not land")
@@ -56,12 +54,13 @@ func TestDuplicateUsername(t *testing.T) {
body, err := json.Marshal(map[string]string{
"username": user.Username,
"display_name": "Someone else",
"password": testPassword,
})
if err != nil {
t.Fatalf("marshal body: %v", err)
}
resp := doRequest(t, http.MethodPost, "/api/v1/users", uuid.Nil, body)
resp := doRequest(t, http.MethodPost, "/api/v1/users", "", body)
requireStatus(t, resp, http.StatusConflict)
var apiErr dto.ErrorResponse
@@ -99,7 +98,7 @@ func TestPagination(t *testing.T) {
path += "&cursor=" + url.QueryEscape(cursor)
}
resp := doRequest(t, http.MethodGet, path, user.ID, nil)
resp := doRequest(t, http.MethodGet, path, user.Token, nil)
requireStatus(t, resp, http.StatusOK)
var page dto.MessagePageResponse