fix: address code review findings
This commit is contained in:
@@ -1068,7 +1068,7 @@ func (g *Graph) checkRouteForChanges(itinerary *Itinerary) bool {
|
||||
break
|
||||
}
|
||||
// Check for significant delay (more than 2x normal duration)
|
||||
if edge.Duration > leg.Cost*2 && leg.Cost > 0 { // simplified delay check
|
||||
if edge.Duration > leg.Duration*2 && leg.Duration > 0 {
|
||||
if !needsReSearch || itinerary.ReSearchReason == string(reasonNone) {
|
||||
needsReSearch = true
|
||||
itinerary.NeedsReSearch = true
|
||||
|
||||
@@ -325,9 +325,6 @@ func TestLazyExpansionDepthLimit(t *testing.T) {
|
||||
// TestRouteReSearchOnChange tests that the route change detection logic correctly
|
||||
// identifies when a route leg has undergone significant changes (cancellation or major delay)
|
||||
// and triggers a re-search to find an updated route.
|
||||
// TestRouteReSearchOnChange tests that the route change detection logic correctly
|
||||
// identifies when a route leg has undergone significant changes (cancellation or major delay)
|
||||
// and triggers a re-search to find an updated route.
|
||||
func TestRouteReSearchOnChange(t *testing.T) {
|
||||
graph := NewGraph()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package routing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"trip-planner/internal/cache"
|
||||
@@ -74,19 +75,23 @@ func (s *SearchCacheService) performYandexSearch(ctx context.Context, from, to,
|
||||
|
||||
// parseItineraryFromBytes parses an itinerary from byte data.
|
||||
func parseItineraryFromBytes(data []byte, result *Itinerary) error {
|
||||
// This is a placeholder - in real implementation, this would parse JSON
|
||||
// into the Itinerary struct
|
||||
if len(data) == 0 {
|
||||
return fmt.Errorf("empty data")
|
||||
}
|
||||
if err := json.Unmarshal(data, result); err != nil {
|
||||
return fmt.Errorf("failed to parse itinerary from bytes: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// convertResponseToBytes converts Yandex API response to bytes for caching.
|
||||
func convertResponseToBytes(resp *yandex.Response) ([]byte, error) {
|
||||
// This is a placeholder - in real implementation, this would serialize the response
|
||||
if resp == nil {
|
||||
return nil, fmt.Errorf("nil response")
|
||||
}
|
||||
return []byte(`{"search":{"from":"%s","to":"%s"},"segments":[]}`), nil
|
||||
data, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal response: %w", err)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ func TestParseItineraryFromBytes(t *testing.T) {
|
||||
t.Error("expected error for empty data")
|
||||
}
|
||||
|
||||
// Test with non-empty data (placeholder implementation returns nil error)
|
||||
err = parseItineraryFromBytes([]byte("test"), &result)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error for non-empty data, got %v", err)
|
||||
// Test with invalid JSON data
|
||||
err = parseItineraryFromBytes([]byte("invalid json data"), &result)
|
||||
if err == nil {
|
||||
t.Error("expected error for invalid JSON data")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user