8dfe7e8b4a
new file: main_dc/yalarba/api_yal/cmd/testrunner/README.md new file: main_dc/yalarba/api_yal/cmd/testrunner/main.go new file: main_dc/yalarba/api_yal/cmd/testrunner/runner.go deleted: main_dc/yalarba/api_yal/test/intergration/auth_integration_test.go deleted: main_dc/yalarba/api_yal/test/intergration/objects_integration_test.go deleted: main_dc/yalarba/api_yal/test/intergration/setup_test.go deleted: main_dc/yalarba/api_yal/test/setup_test.go new file: main_dc/yalarba/api_yal/tests/integration/account_test.go new file: main_dc/yalarba/api_yal/tests/integration/appeal_test.go new file: main_dc/yalarba/api_yal/tests/integration/auth_test.go new file: main_dc/yalarba/api_yal/tests/integration/comment_test.go new file: main_dc/yalarba/api_yal/tests/integration/feedback_test.go new file: main_dc/yalarba/api_yal/tests/integration/object_test.go new file: main_dc/yalarba/api_yal/tests/integration/rating_test.go new file: main_dc/yalarba/api_yal/tests/testutils/client.go new file: main_dc/yalarba/api_yal/tests/testutils/fixtures.go new file: main_dc/yalarba/api_yal/tests/testutils/setup.go write tests
192 lines
6.3 KiB
Go
192 lines
6.3 KiB
Go
package integration
|
|
|
|
import (
|
|
"testing"
|
|
"api_yal/tests/testutils"
|
|
)
|
|
|
|
func TestAppealEndpoints(t *testing.T) {
|
|
config := testutils.NewTestConfig()
|
|
|
|
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",
|
|
"contact_email": user.Email,
|
|
}
|
|
|
|
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create appeal: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != 201 {
|
|
t.Errorf("Expected status 201, got %d", resp.StatusCode)
|
|
}
|
|
|
|
var createdAppeal map[string]interface{}
|
|
if err := config.ParseResponse(resp, &createdAppeal); err != nil {
|
|
t.Fatalf("Failed to parse response: %v", err)
|
|
}
|
|
|
|
if _, ok := createdAppeal["id"]; !ok {
|
|
t.Error("Appeal ID not found")
|
|
}
|
|
})
|
|
|
|
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",
|
|
"contact_email": user.Email,
|
|
}
|
|
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create appeal: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var createdAppeal map[string]interface{}
|
|
if err := config.ParseResponse(resp, &createdAppeal); err != nil {
|
|
t.Fatalf("Failed to parse response: %v", err)
|
|
}
|
|
|
|
appealID := createdAppeal["id"].(float64)
|
|
|
|
getResp, err := config.Request("GET", "/appeals/"+string(rune(appealID)), nil, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to get appeal: %v", err)
|
|
}
|
|
defer getResp.Body.Close()
|
|
|
|
if getResp.StatusCode != 200 {
|
|
t.Errorf("Expected status 200, got %d", getResp.StatusCode)
|
|
}
|
|
})
|
|
|
|
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",
|
|
"contact_email": user.Email,
|
|
}
|
|
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create appeal: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var createdAppeal map[string]interface{}
|
|
if err := config.ParseResponse(resp, &createdAppeal); err != nil {
|
|
t.Fatalf("Failed to parse response: %v", err)
|
|
}
|
|
|
|
appealID := createdAppeal["id"].(float64)
|
|
|
|
updateData := map[string]interface{}{
|
|
"title": "Updated Title",
|
|
"message": "Updated message content",
|
|
"priority": "critical",
|
|
}
|
|
|
|
updateResp, err := config.Request("PUT", "/appeals/"+string(rune(appealID)), updateData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to update appeal: %v", err)
|
|
}
|
|
defer updateResp.Body.Close()
|
|
|
|
if updateResp.StatusCode != 200 {
|
|
t.Errorf("Expected status 200, got %d", updateResp.StatusCode)
|
|
}
|
|
})
|
|
|
|
t.Run("MyAppeals", func(t *testing.T) {
|
|
user := config.CreateTestUser(t)
|
|
defer config.CleanupTestUser(t, user)
|
|
|
|
// Создаем несколько обращений
|
|
for i := 0; i < 3; i++ {
|
|
appealData := map[string]interface{}{
|
|
"type": "other",
|
|
"title": "Test Appeal",
|
|
"message": "Test message content",
|
|
}
|
|
_, err := config.Request("POST", "/appeals", appealData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create appeal: %v", err)
|
|
}
|
|
}
|
|
|
|
resp, err := config.Request("GET", "/appeals/me", nil, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to get my appeals: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != 200 {
|
|
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
|
}
|
|
})
|
|
|
|
t.Run("DeleteAppeal", func(t *testing.T) {
|
|
user := config.CreateTestUser(t)
|
|
defer config.CleanupTestUser(t, user)
|
|
|
|
// Создаем обращение
|
|
appealData := map[string]interface{}{
|
|
"type": "question",
|
|
"title": "To Delete",
|
|
"message": "This appeal will be deleted",
|
|
}
|
|
resp, err := config.Request("POST", "/appeals", appealData, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create appeal: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var createdAppeal map[string]interface{}
|
|
if err := config.ParseResponse(resp, &createdAppeal); err != nil {
|
|
t.Fatalf("Failed to parse response: %v", err)
|
|
}
|
|
|
|
appealID := createdAppeal["id"].(float64)
|
|
|
|
deleteResp, err := config.Request("DELETE", "/appeals/"+string(rune(appealID)), nil, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to delete appeal: %v", err)
|
|
}
|
|
defer deleteResp.Body.Close()
|
|
|
|
if deleteResp.StatusCode != 204 {
|
|
t.Errorf("Expected status 204, got %d", deleteResp.StatusCode)
|
|
}
|
|
|
|
// Проверяем, что обращение удалено
|
|
getResp, err := config.Request("GET", "/appeals/"+string(rune(appealID)), nil, user.Token)
|
|
if err != nil {
|
|
t.Fatalf("Failed to get appeal: %v", err)
|
|
}
|
|
defer getResp.Body.Close()
|
|
|
|
if getResp.StatusCode != 404 {
|
|
t.Errorf("Expected status 404 for deleted appeal, got %d", getResp.StatusCode)
|
|
}
|
|
})
|
|
} |