Skip to content

Commit

Permalink
[559] feat: add option to exclude Outdoor Cycling workouts (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
philosowaffle authored Dec 31, 2023
1 parent d7b08aa commit 7170c44
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions mkdocs/docs/configuration/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ The available values are:

```json
Cycling
Outdoor Cycling
BikeBootcamp
TreadmillRunning
OutdoorRunning
Expand Down
1 change: 1 addition & 0 deletions src/Common/Dto/P2GWorkout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static WorkoutType GetWorkoutType(this Workout workout)
FitnessDiscipline.Caesar => WorkoutType.Rowing,
FitnessDiscipline.Cardio => WorkoutType.Cardio,
FitnessDiscipline.Circuit => WorkoutType.Circuit,
FitnessDiscipline.Cycling when workout.Is_Outdoor => WorkoutType.OutdoorCycling,
FitnessDiscipline.Cycling => WorkoutType.Cycling,
FitnessDiscipline.Meditation => WorkoutType.Meditation,
FitnessDiscipline.Strength => WorkoutType.Strength,
Expand Down
1 change: 1 addition & 0 deletions src/Common/Dto/WorkoutType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum WorkoutType : byte
Yoga = 11,
Meditation = 12,
Rowing = 13,
OutdoorCycling = 14,
}
}
1 change: 1 addition & 0 deletions src/UnitTests/Common/Dto/P2GWorkoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void GetWorkoutType_Should_Map_Correctly([Values]FitnessDiscipline fitnes
case FitnessDiscipline.Cardio: workoutType.Should().Be(WorkoutType.Cardio); break;
case FitnessDiscipline.Caesar: workoutType.Should().Be(WorkoutType.Rowing); break;
case FitnessDiscipline.Circuit: workoutType.Should().Be(WorkoutType.Circuit); break;
case FitnessDiscipline.Cycling when isOutdoor: workoutType.Should().Be(WorkoutType.OutdoorCycling); break;
case FitnessDiscipline.Cycling: workoutType.Should().Be(WorkoutType.Cycling); break;
case FitnessDiscipline.Meditation: workoutType.Should().Be(WorkoutType.Meditation); break;
case FitnessDiscipline.Strength: workoutType.Should().Be(WorkoutType.Strength); break;
Expand Down
46 changes: 46 additions & 0 deletions src/UnitTests/Sync/SyncServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,51 @@ public async Task SyncAsync_When_CheckForUpdates_Disabled_Should_NotCheck()
// ASSERT
ghService.Verify(x => x.GetLatestReleaseInformationAsync("philosowaffle", "peloton-to-garmin", Constants.AppVersion), Times.Never);
}

[Test]
public async Task SyncAsync_When_Should_Excluded_ExcludedWorkoutTypes()
{
// SETUP
var mocker = new AutoMocker();

var service = mocker.CreateInstance<SyncService>();
var peloton = mocker.GetMock<IPelotonService>();
var db = mocker.GetMock<ISyncStatusDb>();
var converter = mocker.GetMock<IConverter>();
var garmin = mocker.GetMock<IGarminUploader>();
var fileHandler = mocker.GetMock<IFileHandling>();
var settingsService = mocker.GetMock<ISettingsService>();

var settings = new Settings();
settings.Format.Fit = true;
settings.App.CheckForUpdates = false;
settings.Peloton.ExcludeWorkoutTypes = new List<WorkoutType>() { WorkoutType.OutdoorCycling };
settingsService.Setup(s => s.GetSettingsAsync()).ReturnsAsync(settings);

var syncStatus = new SyncServiceStatus();
db.Setup(x => x.GetSyncStatusAsync()).Returns(Task.FromResult(syncStatus));

var workout = new Workout() { Status = "COMPLETE", Id = "1", Is_Outdoor = true, Fitness_Discipline = FitnessDiscipline.Cycling };
peloton.Setup(x => x.GetRecentWorkoutsAsync(0)).ReturnsAsync(new List<Workout>() { workout }.AsServiceResult());

var p2gWorkout = new P2GWorkout() { Workout = workout };
peloton.Setup(x => x.GetWorkoutDetailsAsync(It.IsAny<ICollection<Workout>>())).ReturnsAsync(new P2GWorkout[] { p2gWorkout });

// ACT
var response = await service.SyncAsync(0);

// ASSERT
response.SyncSuccess.Should().BeTrue();
response.PelotonDownloadSuccess.Should().BeTrue();
response.ConversionSuccess.Should().BeTrue();
response.UploadToGarminSuccess.Should().BeNull();
response.Errors.Should().BeNullOrEmpty();

peloton.Verify(x => x.GetRecentWorkoutsAsync(0), Times.Once);
converter.Verify(x => x.ConvertAsync(It.IsAny<P2GWorkout>()), Times.Never);
garmin.Verify(x => x.UploadToGarminAsync(), Times.Never);
db.Verify(x => x.UpsertSyncStatusAsync(It.IsAny<SyncServiceStatus>()), Times.Once);
fileHandler.Verify(x => x.Cleanup(It.IsAny<string>()), Times.Never);
}
}
}
1 change: 1 addition & 0 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Features

- [#564] Set a custom title prefix on Workouts
- [#559] Ability to exclude Outdoor Cycling workouts from sycning

## Docker Tags

Expand Down

0 comments on commit 7170c44

Please sign in to comment.