feat: try sync calories

This commit is contained in:
2026-05-20 17:06:32 +02:00
parent 3d240eca81
commit 75b2743e75
3 changed files with 79 additions and 2 deletions
+51
View File
@@ -144,6 +144,57 @@ it('syncs strava activities into workouts', function () {
]);
});
it('syncs strava calories from detailed activities when summaries omit them', function () {
Http::preventStrayRequests();
Http::fake([
'https://www.strava.com/api/v3/athlete/activities*' => Http::response([
[
'id' => 1122334455,
'name' => 'Evening ride',
'sport_type' => 'Ride',
'moving_time' => 2410,
'distance' => 20500.2,
'start_date' => '2026-05-19T17:45:00Z',
],
]),
'https://www.strava.com/api/v3/activities/1122334455*' => Http::response([
'id' => 1122334455,
'name' => 'Evening ride',
'sport_type' => 'Ride',
'moving_time' => 2410,
'calories' => 618.4,
'distance' => 20500.2,
'start_date' => '2026-05-19T17:45:00Z',
]),
]);
$user = User::factory()->create();
StravaConnection::create([
'user_id' => $user->id,
'athlete_id' => 123456,
'access_token' => 'access-token',
'refresh_token' => 'refresh-token',
'expires_at' => now()->addHour(),
'scopes' => ['read', 'activity:read'],
'athlete' => ['id' => 123456],
]);
Sanctum::actingAs($user);
$this
->postJson('/api/strava/sync')
->assertOk()
->assertJsonPath('data.importedCount', 1)
->assertJsonPath('data.fetchedCount', 1);
$this->assertDatabaseHas('workout_sessions', [
'user_id' => $user->id,
'source' => WorkoutSource::STRAVA->value,
'external_id' => '1122334455',
'calories_burned' => 618,
]);
});
it('requires an activity read scope before syncing strava activities', function () {
$user = User::factory()->create();
StravaConnection::create([