On branch main
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
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"api_yal/tests/testutils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAccountEndpoints(t *testing.T) {
|
||||
config := testutils.NewTestConfig()
|
||||
|
||||
t.Run("GetProfile", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
resp, err := config.Request("GET", "/account/profile", nil, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get profile: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var profile map[string]interface{}
|
||||
if err := config.ParseResponse(resp, &profile); err != nil {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
expectedFields := []string{"id", "email", "full_name", "first_name", "last_name", "role", "stats"}
|
||||
for _, field := range expectedFields {
|
||||
if _, ok := profile[field]; !ok {
|
||||
t.Errorf("Expected field %s not found", field)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("GetOwnAccount", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
resp, err := config.Request("GET", "/account", nil, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get account: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("UpdateAccount", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
updateData := map[string]interface{}{
|
||||
"phone": "+79998887766",
|
||||
"city": "Moscow",
|
||||
}
|
||||
|
||||
resp, err := config.Request("PUT", "/account", updateData, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update account: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var updatedAccount map[string]interface{}
|
||||
if err := config.ParseResponse(resp, &updatedAccount); err != nil {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
if phone, ok := updatedAccount["phone"].(string); !ok || phone != "+79998887766" {
|
||||
t.Error("Phone number not updated correctly")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("ChangePassword", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
newPassword := "newpass123"
|
||||
resp, err := config.Request("POST", "/account/change-password", map[string]interface{}{
|
||||
"current_password": user.Password,
|
||||
"new_password": newPassword,
|
||||
}, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to change password: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Проверяем, что можно войти с новым паролем
|
||||
newToken, err := config.GetAuthToken(user.Email, newPassword)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to login with new password: %v", err)
|
||||
}
|
||||
if newToken == "" {
|
||||
t.Error("Failed to get token with new password")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("ChangePasswordWrongCurrent", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
defer config.CleanupTestUser(t, user)
|
||||
|
||||
resp, err := config.Request("POST", "/account/change-password", map[string]interface{}{
|
||||
"current_password": "wrongpassword",
|
||||
"new_password": "newpass123",
|
||||
}, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to change password: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 400 && resp.StatusCode != 401 {
|
||||
t.Errorf("Expected status 400 or 401, got %d", resp.StatusCode)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("DeleteAccount", func(t *testing.T) {
|
||||
user := config.CreateTestUser(t)
|
||||
|
||||
resp, err := config.Request("DELETE", "/account", nil, user.Token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to delete account: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Проверяем, что больше нельзя войти
|
||||
_, err = config.GetAuthToken(user.Email, user.Password)
|
||||
if err == nil {
|
||||
t.Error("Should not be able to login after account deletion")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("UnauthorizedAccess", func(t *testing.T) {
|
||||
resp, err := config.Request("GET", "/account/profile", nil, "")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to make request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 401 {
|
||||
t.Errorf("Expected status 401, got %d", resp.StatusCode)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user