mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
hot fix #1
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPacketaService_GetPacketStatus_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
t.Fatalf("expected POST request, got %s", r.Method)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read request body: %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Contains(body, []byte("<packetStatus>")) {
|
||||
t.Fatalf("expected packetStatus XML request, got: %s", string(body))
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/xml")
|
||||
_, _ = w.Write([]byte(`
|
||||
<response>
|
||||
<status>ok</status>
|
||||
<result>
|
||||
<statusCode>DELIVERED</statusCode>
|
||||
<statusText>DELIVERED</statusText>
|
||||
</result>
|
||||
</response>
|
||||
`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
service := &PacketaService{
|
||||
ApiPassword: "test-password",
|
||||
ApiUrl: server.URL,
|
||||
EshopName: "TestEshop",
|
||||
}
|
||||
|
||||
status, err := service.GetPacketStatus("12345")
|
||||
if err != nil {
|
||||
t.Fatalf("GetPacketStatus returned error: %v", err)
|
||||
}
|
||||
|
||||
if status != "DELIVERED" {
|
||||
t.Fatalf("expected status 'DELIVERED', got %q", status)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user