On branch main
modified: main_dc/yalarba/api_yal/cmd/testrunner/main.go modified: main_dc/yalarba/api_yal/cmd/testrunner/runner.go modified: main_dc/yalarba/api_yal/tests/integration/account_test.go modified: main_dc/yalarba/api_yal/tests/integration/appeal_test.go modified: main_dc/yalarba/api_yal/tests/integration/auth_test.go modified: main_dc/yalarba/api_yal/tests/integration/comment_test.go modified: main_dc/yalarba/api_yal/tests/integration/feedback_test.go modified: main_dc/yalarba/api_yal/tests/integration/object_test.go modified: main_dc/yalarba/api_yal/tests/integration/rating_test.go deleted: main_dc/yalarba/api_yal/tests/testutils/client.go modified: main_dc/yalarba/api_yal/tests/testutils/fixtures.go modified: main_dc/yalarba/api_yal/tests/testutils/setup.go write comments for and into test's functions
This commit is contained in:
@@ -5,19 +5,22 @@ import (
|
||||
"api_yal/tests/testutils"
|
||||
)
|
||||
|
||||
// TestAppealEndpoints тестирует все эндпоинты для работы с обращениями пользователей
|
||||
// Включает создание, получение, обновление, удаление обращений и получение списка своих обращений
|
||||
func TestAppealEndpoints(t *testing.T) {
|
||||
config := testutils.NewTestConfig()
|
||||
|
||||
// CreateAppeal тестирует создание нового обращения
|
||||
t.Run("CreateAppeal", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
appealData := map[string]interface{}{
|
||||
"type": "complaint",
|
||||
"title": "Test Appeal",
|
||||
"message": "This is a test appeal message for testing purposes",
|
||||
"priority": "high",
|
||||
"contact_name": "Test User",
|
||||
"type": "complaint",
|
||||
"title": "Test Appeal",
|
||||
"message": "This is a test appeal message for testing purposes",
|
||||
"priority": "high",
|
||||
"contact_name": "Test User",
|
||||
"contact_email": user.Email,
|
||||
}
|
||||
|
||||
@@ -27,6 +30,7 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Ожидаем статус 201 Created
|
||||
if resp.StatusCode != 201 {
|
||||
t.Errorf("Expected status 201, got %d", resp.StatusCode)
|
||||
}
|
||||
@@ -36,20 +40,22 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
// Проверяем, что ID обращения присутствует в ответе
|
||||
if _, ok := createdAppeal["id"]; !ok {
|
||||
t.Error("Appeal ID not found")
|
||||
}
|
||||
})
|
||||
|
||||
// GetAppealByID тестирует получение обращения по ID
|
||||
t.Run("GetAppealByID", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
// Создаем обращение
|
||||
appealData := map[string]interface{}{
|
||||
"type": "question",
|
||||
"title": "Test Question",
|
||||
"message": "This is a test question",
|
||||
"type": "question",
|
||||
"title": "Test Question",
|
||||
"message": "This is a test question",
|
||||
"contact_email": user.Email,
|
||||
}
|
||||
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
||||
@@ -76,15 +82,16 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// UpdateAppeal тестирует обновление существующего обращения
|
||||
t.Run("UpdateAppeal", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
// Создаем обращение
|
||||
appealData := map[string]interface{}{
|
||||
"type": "suggestion",
|
||||
"title": "Original Title",
|
||||
"message": "Original message for testing",
|
||||
"type": "suggestion",
|
||||
"title": "Original Title",
|
||||
"message": "Original message for testing",
|
||||
"contact_email": user.Email,
|
||||
}
|
||||
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
||||
@@ -117,6 +124,7 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// MyAppeals тестирует получение списка обращений текущего пользователя
|
||||
t.Run("MyAppeals", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
@@ -145,6 +153,7 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// DeleteAppeal тестирует удаление обращения
|
||||
t.Run("DeleteAppeal", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
@@ -174,11 +183,12 @@ func TestAppealEndpoints(t *testing.T) {
|
||||
}
|
||||
defer deleteResp.Body.Close()
|
||||
|
||||
// Ожидаем статус 204 No Content при успешном удалении
|
||||
if deleteResp.StatusCode != 204 {
|
||||
t.Errorf("Expected status 204, got %d", deleteResp.StatusCode)
|
||||
}
|
||||
|
||||
// Проверяем, что обращение удалено
|
||||
// Проверяем, что обращение удалено - должно вернуть 404
|
||||
getResp, err := config.Request("GET", "/appeals/"+string(rune(appealID)), nil, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get appeal: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user