Skip to content

Commit

Permalink
Add strava tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Oct 17, 2023
1 parent a955aa1 commit 70d9d73
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public WebDriver getLocalWebDriver() {
public WebDriver getRemoteWebDriver() throws MalformedURLException {
ChromeOptions options = new ChromeOptions().addArguments("--headless",
"--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage",
"--window-size=1920,1080", "--remote-allow-origins=*");
"--remote-allow-origins=*");

RemoteWebDriver driver = new RemoteWebDriver(new URL(apiUri), options, false);
driver.setLogLevel(Level.WARNING);
Expand Down
11 changes: 10 additions & 1 deletion test/docker-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const config = {
SPRING_ACTUATOR_PORT: 8082,
SPRING_ADMIN_SERVER_HOST: "localhost",
SPRING_ADMIN_SERVER_PORT: 9090,
WEBDRIVER_API_URI: "http://chrome:4444/wd/hub",
WEBDRIVER_API_URI: "http://chrome:4444/",
WITHINGS_ACCOUNTS_URI: `http://${
dockerNetwork ? "reverse-proxy" : "localhost:9780"
}/withings`,
Expand Down Expand Up @@ -83,6 +83,15 @@ const config = {
arch === "arm64"
? "seleniarm/standalone-chromium:116.0-chromedriver-116.0-grid-4.10.0-20230828"
: "selenium/standalone-chrome:116.0-chromedriver-116.0-grid-4.12.1-20230912",
environment: {
SE_SCREEN_WIDTH: 1920,
SE_SCREEN_HEIGHT: 1080,
SE_SESSION_RETRY_INTERVAL: 1,
SE_NODE_MAX_SESSIONS: 10,
SE_NODE_OVERRIDE_MAX_SESSIONS: true,
START_XVFB: false,
SE_DRAIN_AFTER_SESSION_COUNT: 5,
},
healthcheck: {
test: [
"CMD",
Expand Down
141 changes: 19 additions & 122 deletions test/mock_strava/activities.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const { getSearchParams } = require("./request");

let activity1Date = new Date();
let activity2Date = new Date();

function getActivities(request, response) {
const authorization = request.headers.authorization;
if (authorization !== "Bearer test-access-token") {
Expand All @@ -7,6 +12,14 @@ function getActivities(request, response) {
return;
}

const searchParams = getSearchParams(request);
const after = parseInt(searchParams.get("after"));
const before = parseInt(searchParams.get("before"));
activity1Date = new Date(1000 * (after + (before - after) / 2));
activity1Date.setUTCHours(12, 35);
activity2Date = new Date(1000 * (after + (before - after) / 2));
activity2Date.setUTCHours(12, 45);

response.writeHead(200, {
"Content-Type": "application/json",
});
Expand Down Expand Up @@ -163,8 +176,12 @@ function getActivity(request, response) {
total_elevation_gain: 516,
type: "Ride",
sport_type: "MountainBikeRide",
start_date: "2018-02-16T14:52:54Z",
start_date_local: "2018-02-16T06:52:54Z",
start_date: request.url.endsWith("1")
? activity1Date.toISOString()
: activity2Date.toISOString(),
start_date_local: request.url.endsWith("1")
? activity1Date.toISOString()
: activity2Date.toISOString(),
timezone: "(GMT-08:00) America/Los_Angeles",
utc_offset: -28800,
start_latlng: [37.83, -122.26],
Expand All @@ -174,14 +191,6 @@ function getActivity(request, response) {
comment_count: 0,
athlete_count: 1,
photo_count: 0,
map: {
id: "a1410355832",
polyline:
"ki{eFvqfiVqAWQIGEEKAYJgBVqDJ{BHa@jAkNJw@Pw@V{APs@^aABQAOEQGKoJ_FuJkFqAo@{A}@sH{DiAs@Q]?WVy@`@oBt@_CB]KYMMkB{AQEI@WT{BlE{@zAQPI@ICsCqA_BcAeCmAaFmCqIoEcLeG}KcG}A}@cDaBiDsByAkAuBqBi@y@_@o@o@kB}BgIoA_EUkAMcACa@BeBBq@LaAJe@b@uA`@_AdBcD`@iAPq@RgALqAB{@EqAyAoOCy@AmCBmANqBLqAZkB\\iCPiBJwCCsASiCq@iD]eA]y@[i@w@mAa@i@k@g@kAw@i@Ya@Q]EWFMLa@~BYpAFNpA`Aj@n@X`@V`AHh@JfB@xAMvAGZGHIDIAWOEQNcC@sACYK[MSOMe@QKKKYOs@UYQISCQ?Q@WNo@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fBVpAd@`BfBlFf@fBdA~Cr@pAz@fApBhBjAt@H?IL?FBFJLx@^lHvDvh@~XnElCbAd@pGhDbAb@nAr@`Ad@`GhDnBbAxCbBrWhNJJDPARGP_@t@Qh@]pAUtAoA`Ny@jJApBBNFLJFJBv@Hb@HBF?\\",
resource_state: 3,
summary_polyline:
"ki{eFvqfiVsBmA`Feh@qg@iX`B}JeCcCqGjIq~@kf@cM{KeHeX`@_GdGkSeBiXtB}YuEkPwFyDeAzAe@pC~DfGc@bIOsGmCcEiD~@oBuEkFhBcBmDiEfAVuDiAuD}NnDaNiIlCyDD_CtJKv@wGhD]YyEzBo@g@uKxGmHpCGtEtI~AuLrHkAcAaIvEgH_EaDR_FpBuBg@sNxHqEtHgLoTpIiCzKNr[sB|Es\\`JyObYeMbGsMnPsAfDxAnD}DBu@bCx@{BbEEyAoD`AmChNoQzMoGhOwX|[yIzBeFKg[zAkIdU_LiHxK}HzEh@vM_BtBg@xGzDbCcF~GhArHaIfByAhLsDiJuC?_HbHd@nL_Cz@ZnEkDDy@hHwJLiCbIrNrIvN_EfAjDWlEnEiAfBxDlFkBfBtEfDaAzBvDKdFx@|@XgJmDsHhAgD`GfElEzOwBnYdBxXgGlSc@bGdHpW|HdJztBnhAgFxc@HnCvBdA",
},
trainer: false,
commute: false,
manual: false,
Expand All @@ -208,96 +217,6 @@ function getActivity(request, response) {
suffer_score: null,
description: "",
calories: 870.2,
segment_efforts: [
{
id: 12345678987654321,
resource_state: 2,
name: "Tunnel Rd.",
activity: {
id: 12345678987654321,
resource_state: 1,
},
athlete: {
id: 134815,
resource_state: 1,
},
elapsed_time: 2038,
moving_time: 2038,
start_date: "2018-02-16T14:56:25Z",
start_date_local: "2018-02-16T06:56:25Z",
distance: 9434.8,
start_index: 211,
end_index: 2246,
average_cadence: 78.6,
device_watts: true,
average_watts: 237.6,
segment: {
id: 673683,
resource_state: 2,
name: "Tunnel Rd.",
activity_type: "Ride",
distance: 9220.7,
average_grade: 4.2,
maximum_grade: 25.8,
elevation_high: 426.5,
elevation_low: 43.4,
start_latlng: [37.8346153, -122.2520872],
end_latlng: [37.8476261, -122.2008944],
climb_category: 3,
city: "Oakland",
state: "CA",
country: "United States",
private: false,
hazardous: false,
starred: false,
},
kom_rank: null,
pr_rank: null,
achievements: [],
hidden: false,
},
],
splits_metric: [
{
distance: 1001.5,
elapsed_time: 141,
elevation_difference: 4.4,
moving_time: 141,
split: 1,
average_speed: 7.1,
pace_zone: 0,
},
],
laps: [
{
id: 4479306946,
resource_state: 2,
name: "Lap 1",
activity: {
id: 1410355832,
resource_state: 1,
},
athlete: {
id: 134815,
resource_state: 1,
},
elapsed_time: 1573,
moving_time: 1569,
start_date: "2018-02-16T14:52:54Z",
start_date_local: "2018-02-16T06:52:54Z",
distance: 8046.72,
start_index: 0,
end_index: 1570,
total_elevation_gain: 276,
average_speed: 5.12,
max_speed: 9.5,
average_cadence: 78.6,
device_watts: true,
average_watts: 233.1,
lap_index: 1,
split: 1,
},
],
gear: {
id: "b12345678987654321",
primary: true,
Expand All @@ -306,28 +225,6 @@ function getActivity(request, response) {
distance: 32547610,
},
partner_brand_tag: null,
photos: {
primary: {
id: null,
unique_id: "3FDGKL3-204E-4867-9E8D-89FC79EAAE17",
urls: {
100: "https://dgtzuqphqg23d.cloudfront.net/Bv93zv5t_mr57v0wXFbY_JyvtucgmU5Ym6N9z_bKeUI-128x96.jpg",
600: "https://dgtzuqphqg23d.cloudfront.net/Bv93zv5t_mr57v0wXFbY_JyvtucgmU5Ym6N9z_bKeUI-768x576.jpg",
},
source: 1,
},
use_primary_photo: true,
count: 2,
},
highlighted_kudosers: [
{
destination_url: "strava://athletes/12345678987654321",
display_name: "Marianne V.",
avatar_url:
"https://dgalywyr863hv.cloudfront.net/pictures/athletes/12345678987654321/12345678987654321/3/medium.jpg",
show_name: true,
},
],
hide_from_home: false,
device_name: "Garmin Edge 1030",
embed_token: "18e4615989b47dd4ff3dc711b0aa4502e4b311a9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public class BaseIntegrationTest {
JdbcTemplate jdbcTemplate;

WebDriverWait wait;
WebDriverWait longWait;

public void setupMocks() {
wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
longWait = new WebDriverWait(webDriver, Duration.ofSeconds(15));
cleanupDB();
jdbcTemplate.execute("INSERT INTO oauth2_authorized_client (" + //
"client_registration_id," + //
Expand Down
78 changes: 43 additions & 35 deletions test/src/test/java/io/github/mucsi96/workout/test/RideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

class RideTest extends BaseIntegrationTest {

Expand Down Expand Up @@ -169,38 +170,42 @@ void beforeEach() {
""", Timestamp.from(Instant.now().minus(1, ChronoUnit.DAYS))));
}

// @Test
// void display_todays_weight() {
// open();
// WebElement weighElement = webDriver
// .findElement(By.xpath("//h2[contains(text(),
// \"Weight\")]/following-sibling::*"));
// assertThat(weighElement.getText()).isEqualToIgnoringWhitespace("87.2 kg");
// WebElement bodyFatElement = webDriver
// .findElement(By.xpath("//h2[contains(text(), \"Body
// fat\")]/following-sibling::*"));
// assertThat(bodyFatElement.getText()).isEqualToIgnoringWhitespace("21.8 kg");
// WebElement fatRatioElement = webDriver
// .findElement(By.xpath("//h2[contains(text(), \"Fat
// ratio\")]/following-sibling::*"));
// assertThat(fatRatioElement.getText()).isEqualToIgnoringWhitespace("35.3 %");
// }
@Test
void display_todays_ride_stats() {
open();
wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//h2[contains(text(),\"Calories\")]")));
WebElement caloriesElement = webDriver
.findElement(By.xpath("//h2[contains(text(),\"Calories\")]/following-sibling::*"));
assertThat(caloriesElement.getText()).isEqualTo("1 740");
WebElement elevationGainElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Elevation gain\")]/following-sibling::*"));
assertThat(elevationGainElement.getText()).isEqualTo("1 032 m");
WebElement distanceElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Distance\")]/following-sibling::*"));
assertThat(distanceElement.getText()).isEqualTo("56 km");
WebElement timeElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Time\")]/following-sibling::*"));
assertThat(timeElement.getText()).isEqualTo("2 h 20 min");
}

@Test
void display_ride_stats_for_week() {
open();
wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//h2[contains(text(),\"Calories\")]")));
WebElement caloriesElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Calories\")]/following-sibling::*/following-sibling::*"));
assertThat(caloriesElement.getText()).isEqualToIgnoringWhitespace("1 938");
assertThat(caloriesElement.getText()).isEqualTo("3 678");
WebElement elevationGainElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Elevation gain\")]/following-sibling::*/following-sibling::*"));
assertThat(elevationGainElement.getText()).isEqualToIgnoringWhitespace("1 224 m");
assertThat(elevationGainElement.getText()).isEqualTo("2 256 m");
WebElement distanceElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Distance\")]/following-sibling::*/following-sibling::*"));
assertThat(distanceElement.getText()).isEqualToIgnoringWhitespace("35 km");
assertThat(distanceElement.getText()).isEqualTo("91 km");
WebElement timeElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Time\")]/following-sibling::*/following-sibling::*"));
assertThat(timeElement.getText()).isEqualToIgnoringWhitespace("2 h 34 min");
assertThat(timeElement.getText()).isEqualTo("4 h 54 min");
}

@Test
Expand All @@ -211,19 +216,20 @@ void display_ride_stats_for_month() {
By.xpath("//a[contains(text(), \"Month\")]"));
button.click();
waitForLoad();

wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//h2[contains(text(),\"Calories\")]")));
WebElement caloriesElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Calories\")]/following-sibling::*/following-sibling::*"));
assertThat(caloriesElement.getText()).isEqualToIgnoringWhitespace("2 584");
assertThat(caloriesElement.getText()).isEqualTo("4 324");
WebElement elevationGainElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Elevation gain\")]/following-sibling::*/following-sibling::*"));
assertThat(elevationGainElement.getText()).isEqualToIgnoringWhitespace("1 632 m");
assertThat(elevationGainElement.getText()).isEqualTo("2 664 m");
WebElement distanceElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Distance\")]/following-sibling::*/following-sibling::*"));
assertThat(distanceElement.getText()).isEqualToIgnoringWhitespace("47 km");
assertThat(distanceElement.getText()).isEqualTo("103 km");
WebElement timeElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Time\")]/following-sibling::*/following-sibling::*"));
assertThat(timeElement.getText()).isEqualToIgnoringWhitespace("3 h 25 min");
assertThat(timeElement.getText()).isEqualTo("5 h 45 min");
}

@Test
Expand All @@ -234,19 +240,20 @@ void display_ride_stats_for_year() {
By.xpath("//a[contains(text(), \"Year\")]"));
button.click();
waitForLoad();

wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//h2[contains(text(),\"Calories\")]")));
WebElement caloriesElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Calories\")]/following-sibling::*/following-sibling::*"));
assertThat(caloriesElement.getText()).isEqualToIgnoringWhitespace("3 230");
assertThat(caloriesElement.getText()).isEqualTo("4 970");
WebElement elevationGainElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Elevation gain\")]/following-sibling::*/following-sibling::*"));
assertThat(elevationGainElement.getText()).isEqualToIgnoringWhitespace("2 040 m");
assertThat(elevationGainElement.getText()).isEqualTo("3 072 m");
WebElement distanceElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Distance\")]/following-sibling::*/following-sibling::*"));
assertThat(distanceElement.getText()).isEqualToIgnoringWhitespace("59 km");
assertThat(distanceElement.getText()).isEqualTo("115 km");
WebElement timeElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Time\")]/following-sibling::*/following-sibling::*"));
assertThat(timeElement.getText()).isEqualToIgnoringWhitespace("4 h 16 min");
assertThat(timeElement.getText()).isEqualTo("6 h 36 min");
}

@Test
Expand All @@ -257,19 +264,20 @@ void display_ride_stats_for_all_time() {
By.xpath("//a[contains(text(), \"All time\")]"));
button.click();
waitForLoad();

wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//h2[contains(text(),\"Calories\")]")));
WebElement caloriesElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Calories\")]/following-sibling::*/following-sibling::*"));
assertThat(caloriesElement.getText()).isEqualToIgnoringWhitespace("4746");
assertThat(caloriesElement.getText()).isEqualTo("5 616");
WebElement elevationGainElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Elevation gain\")]/following-sibling::*/following-sibling::*"));
assertThat(elevationGainElement.getText()).isEqualToIgnoringWhitespace("2 964 m");
assertThat(elevationGainElement.getText()).isEqualTo("3 480 m");
WebElement distanceElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Distance\")]/following-sibling::*/following-sibling::*"));
assertThat(distanceElement.getText()).isEqualToIgnoringWhitespace("99 km");
assertThat(distanceElement.getText()).isEqualTo("127 km");
WebElement timeElement = webDriver
.findElement(By.xpath("//h2[contains(text(), \"Time\")]/following-sibling::*/following-sibling::*"));
assertThat(timeElement.getText()).isEqualToIgnoringWhitespace("6 h 18 min");
assertThat(timeElement.getText()).isEqualTo("7 h 28 min");
}

}
Loading

0 comments on commit 70d9d73

Please sign in to comment.