Removed deprecated text fields and WindowMinutes from the observations endpoint
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -142,12 +142,21 @@ func TestObservationsCurrentReturnsUSUnits(t *testing.T) {
|
|||||||
if _, exists := summary["temperatureC"]; exists {
|
if _, exists := summary["temperatureC"]; exists {
|
||||||
t.Fatalf("did not expect metric key temperatureC in US response")
|
t.Fatalf("did not expect metric key temperatureC in US response")
|
||||||
}
|
}
|
||||||
|
if _, exists := summary["windowMinutes"]; exists {
|
||||||
|
t.Fatalf("did not expect deprecated key windowMinutes in observations summary")
|
||||||
|
}
|
||||||
|
|
||||||
conditions := payload["conditions"].([]any)
|
conditions := payload["conditions"].([]any)
|
||||||
first := conditions[0].(map[string]any)
|
first := conditions[0].(map[string]any)
|
||||||
if got := first["temperatureF"].(float64); got != 50.0 {
|
if got := first["temperatureF"].(float64); got != 50.0 {
|
||||||
t.Fatalf("expected conditions[0].temperatureF=50.0, got %v", got)
|
t.Fatalf("expected conditions[0].temperatureF=50.0, got %v", got)
|
||||||
}
|
}
|
||||||
|
if _, exists := first["providerRawDescription"]; exists {
|
||||||
|
t.Fatalf("did not expect deprecated key providerRawDescription in observations condition")
|
||||||
|
}
|
||||||
|
if _, exists := first["conditionText"]; exists {
|
||||||
|
t.Fatalf("did not expect deprecated key conditionText in observations condition")
|
||||||
|
}
|
||||||
|
|
||||||
if obsRepo.summaryWin != constants.ObservationWindow || obsRepo.conditionsWin != constants.ObservationWindow || obsRepo.precipWin != constants.ObservationWindow {
|
if obsRepo.summaryWin != constants.ObservationWindow || obsRepo.conditionsWin != constants.ObservationWindow || obsRepo.precipWin != constants.ObservationWindow {
|
||||||
t.Fatalf("expected observation window %s to be used", constants.ObservationWindow)
|
t.Fatalf("expected observation window %s to be used", constants.ObservationWindow)
|
||||||
@@ -273,6 +282,9 @@ func TestNullFieldsAreOmittedFromJSON(t *testing.T) {
|
|||||||
if _, exists := summary["temperatureF"]; exists {
|
if _, exists := summary["temperatureF"]; exists {
|
||||||
t.Fatalf("expected summary.temperatureF to be omitted when nil")
|
t.Fatalf("expected summary.temperatureF to be omitted when nil")
|
||||||
}
|
}
|
||||||
|
if _, exists := summary["windowMinutes"]; exists {
|
||||||
|
t.Fatalf("expected summary.windowMinutes to be omitted")
|
||||||
|
}
|
||||||
|
|
||||||
conditions := obsPayload["conditions"].([]any)
|
conditions := obsPayload["conditions"].([]any)
|
||||||
firstCond := conditions[0].(map[string]any)
|
firstCond := conditions[0].(map[string]any)
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ type CurrentResponse struct {
|
|||||||
type SummaryResponse struct {
|
type SummaryResponse struct {
|
||||||
TemperatureF *float64 `json:"temperatureF,omitempty"`
|
TemperatureF *float64 `json:"temperatureF,omitempty"`
|
||||||
ApparentTemperatureF *float64 `json:"apparentTemperatureF,omitempty"`
|
ApparentTemperatureF *float64 `json:"apparentTemperatureF,omitempty"`
|
||||||
WindowMinutes int `json:"windowMinutes"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConditionResponse struct {
|
type ConditionResponse struct {
|
||||||
@@ -36,8 +35,6 @@ type ConditionResponse struct {
|
|||||||
ObservedAt time.Time `json:"observedAt"`
|
ObservedAt time.Time `json:"observedAt"`
|
||||||
TemperatureF *float64 `json:"temperatureF,omitempty"`
|
TemperatureF *float64 `json:"temperatureF,omitempty"`
|
||||||
TextDescription *string `json:"textDescription,omitempty"`
|
TextDescription *string `json:"textDescription,omitempty"`
|
||||||
ProviderRawDescription *string `json:"providerRawDescription,omitempty"`
|
|
||||||
ConditionText *string `json:"conditionText,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetCurrent(ctx context.Context) (CurrentResponse, error) {
|
func (s *Service) GetCurrent(ctx context.Context) (CurrentResponse, error) {
|
||||||
@@ -67,8 +64,6 @@ func (s *Service) GetCurrent(ctx context.Context) (CurrentResponse, error) {
|
|||||||
ObservedAt: c.ObservedAt,
|
ObservedAt: c.ObservedAt,
|
||||||
TemperatureF: s.converter.TemperatureCToOutput(c.TemperatureC),
|
TemperatureF: s.converter.TemperatureCToOutput(c.TemperatureC),
|
||||||
TextDescription: c.TextDescription,
|
TextDescription: c.TextDescription,
|
||||||
ProviderRawDescription: c.ProviderRawDescription,
|
|
||||||
ConditionText: c.ConditionText,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +71,6 @@ func (s *Service) GetCurrent(ctx context.Context) (CurrentResponse, error) {
|
|||||||
Summary: SummaryResponse{
|
Summary: SummaryResponse{
|
||||||
TemperatureF: s.converter.TemperatureCToOutput(summary.TemperatureC),
|
TemperatureF: s.converter.TemperatureCToOutput(summary.TemperatureC),
|
||||||
ApparentTemperatureF: s.converter.TemperatureCToOutput(summary.ApparentTemperatureC),
|
ApparentTemperatureF: s.converter.TemperatureCToOutput(summary.ApparentTemperatureC),
|
||||||
WindowMinutes: int(s.window / time.Minute),
|
|
||||||
},
|
},
|
||||||
Conditions: conditions,
|
Conditions: conditions,
|
||||||
PrecipitationEvents: precip,
|
PrecipitationEvents: precip,
|
||||||
|
|||||||
Reference in New Issue
Block a user