aboutsummaryrefslogtreecommitdiff
path: root/web/server_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/server_test.go')
-rw-r--r--web/server_test.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/web/server_test.go b/web/server_test.go
index e90f69a..440ac5f 100644
--- a/web/server_test.go
+++ b/web/server_test.go
@@ -244,6 +244,7 @@ func TestBuildRideProfileIncludesOfficialClimbMatch(t *testing.T) {
Name: "Col de Test",
StartCoord: parsed.Coords[0],
EndCoord: parsed.Coords[1],
+ Sample: parsed.Sample(0, 1),
}}, official_climb.DefaultMatchPolicy())
require.Len(t, profile.Climbs, 1)
@@ -261,6 +262,7 @@ func TestBuildRideProfileUsesOfficialClimbBoundaries(t *testing.T) {
Name: "Col de Test",
StartCoord: parsed.Coords[0],
EndCoord: parsed.Coords[2],
+ Sample: parsed.Sample(0, 2),
}}, official_climb.DefaultMatchPolicy())
require.Len(t, profile.Climbs, 1)
@@ -314,6 +316,9 @@ func TestHandlerCreatesOfficialClimbFromRoutePoints(t *testing.T) {
assert.Equal(t, "Col de Test", climbs[0].Name)
assert.Equal(t, geodist.Coord{Lat: 43.0, Lon: 5.0}, climbs[0].StartCoord)
assert.Equal(t, geodist.Coord{Lat: 43.005, Lon: 5.005}, climbs[0].EndCoord)
+ require.NotNil(t, climbs[0].Sample)
+ assert.Equal(t, 200.0, climbs[0].Sample.ElevationGainM)
+ assert.InDelta(t, 689, climbs[0].Sample.DistanceM, 2)
getRequest = httptest.NewRequest(http.MethodGet, fmt.Sprintf("/rides/%d?official_climb=created", item.ID), nil)
getResponse = httptest.NewRecorder()
@@ -952,6 +957,9 @@ func TestPreviewParsesGPXWithoutPersisting(t *testing.T) {
assert.Contains(t, body, "ride-route")
assert.Contains(t, body, "ride-profile")
assert.Contains(t, body, "data-official-climb-form")
+ assert.Contains(t, body, `name="sample_distance_m"`)
+ assert.Contains(t, body, `name="sample_elevation_gain_m"`)
+ assert.Contains(t, body, `name="start_lat"`)
assert.NotContains(t, body, "Curation")
var count int
require.NoError(t, db.QueryRow("SELECT COUNT(*) FROM rides").Scan(&count))
@@ -979,13 +987,15 @@ func TestPreviewShowsInlineErrorForInvalidRideFile(t *testing.T) {
func TestPreviewCreatesOfficialClimbWithoutPersistingRide(t *testing.T) {
server, db := newWebTestServer(t)
form := url.Values{
- "name": {"Col du Preview"},
- "start_index": {"0"},
- "end_index": {"2"},
- "start_lat": {"43.0"},
- "start_lon": {"5.0"},
- "end_lat": {"43.01"},
- "end_lon": {"5.01"},
+ "name": {"Col du Preview"},
+ "start_index": {"0"},
+ "end_index": {"2"},
+ "start_lat": {"43.0"},
+ "start_lon": {"5.0"},
+ "end_lat": {"43.01"},
+ "end_lon": {"5.01"},
+ "sample_distance_m": {"1400"},
+ "sample_elevation_gain_m": {"200"},
}
request := httptest.NewRequest(http.MethodPost, "/preview/official-climbs", strings.NewReader(form.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -996,6 +1006,9 @@ func TestPreviewCreatesOfficialClimbWithoutPersistingRide(t *testing.T) {
require.NoError(t, err)
require.Len(t, climbs, 1)
assert.Equal(t, "Col du Preview", climbs[0].Name)
+ require.NotNil(t, climbs[0].Sample)
+ assert.Equal(t, 1400.0, climbs[0].Sample.DistanceM)
+ assert.Equal(t, 200.0, climbs[0].Sample.ElevationGainM)
var count int
require.NoError(t, db.QueryRow("SELECT COUNT(*) FROM rides").Scan(&count))
assert.Equal(t, 0, count, "preview climb creation must not persist a ride")