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,94 @@
|
||||
package testutils
|
||||
|
||||
import "testing"
|
||||
|
||||
type CreateObjectRequest struct {
|
||||
ShortName string `json:"short_name"`
|
||||
LongName string `json:"long_name"`
|
||||
Type string `json:"type"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Site string `json:"site"`
|
||||
ShortDescription string `json:"short_description"`
|
||||
Description string `json:"description"`
|
||||
Address string `json:"address"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
IsActive bool `json:"is_active"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
}
|
||||
|
||||
type CreateFeedbackRequest struct {
|
||||
ObjectID uint `json:"object_id"`
|
||||
Rating int `json:"rating"`
|
||||
Text string `json:"text"`
|
||||
Platform string `json:"platform"`
|
||||
MediaURLs []string `json:"media_urls"`
|
||||
}
|
||||
|
||||
type CreateCommentRequest struct {
|
||||
FeedbackID uint `json:"feedback_id"`
|
||||
Text string `json:"text"`
|
||||
ParentID *uint `json:"parent_id"`
|
||||
}
|
||||
|
||||
func (c *TestConfig) CreateTestObject(t *testing.T, token string) uint {
|
||||
req := CreateObjectRequest{
|
||||
ShortName: "Test Object",
|
||||
LongName: "Test Object for Testing",
|
||||
Type: "cafe",
|
||||
Phone: "+71234567890",
|
||||
Email: "test@object.com",
|
||||
Site: "https://test.com",
|
||||
ShortDescription: "Test description",
|
||||
Description: "Full test description",
|
||||
Address: "Test Address 123",
|
||||
Latitude: 55.751244,
|
||||
Longitude: 37.618423,
|
||||
IsActive: true,
|
||||
IsVerified: false,
|
||||
}
|
||||
|
||||
resp, err := c.Request("POST", "/objects", req, token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test object: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := c.ParseResponse(resp, &result); err != nil {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
if id, ok := result["id"].(float64); ok {
|
||||
return uint(id)
|
||||
}
|
||||
t.Fatal("Failed to get object ID")
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *TestConfig) CreateTestFeedback(t *testing.T, token string, objectID uint) uint {
|
||||
req := CreateFeedbackRequest{
|
||||
ObjectID: objectID,
|
||||
Rating: 5,
|
||||
Text: "Test feedback content",
|
||||
Platform: "tourist",
|
||||
}
|
||||
|
||||
resp, err := c.Request("POST", "/feedbacks", req, token)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test feedback: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := c.ParseResponse(resp, &result); err != nil {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
if id, ok := result["id"].(float64); ok {
|
||||
return uint(id)
|
||||
}
|
||||
t.Fatal("Failed to get feedback ID")
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user