Skip to content

Commit 178bc9a

Browse files
author
OpenClaw Assistant
committed
fix: add HIIT activity type support for Strava mapping
- Add 'HIIT' to sportTypeMapping in StravaActivityMapper.ts - Map Strava sport_type 'HIIT' to activity type 'HIIT' - Add test case for HIIT activity mapping - Add test case for HIIT activity type detection - All existing tests continue to pass
1 parent 490e1ca commit 178bc9a

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

apps/web/lib/services/StravaActivityMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class StravaActivityMapper {
7272
'Strength Training': ['WeightTraining', 'Workout'],
7373
'Walking': ['Walk', 'Hike'],
7474
'Yoga': ['Yoga'],
75+
'HIIT': ['HIIT'],
7576
};
7677

7778
if (!this.fetchActivityTypes) {

apps/web/tests/api/strava-mapping.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ const stravaWorkoutActivity: StravaActivity = {
8181
flagged: false
8282
};
8383

84+
const stravaHIITActivity: StravaActivity = {
85+
id: 55443322,
86+
name: "HIIT Workout",
87+
type: "HIIT",
88+
sport_type: "HIIT",
89+
start_date: "2024-03-15T17:00:00Z",
90+
elapsed_time: 1800, // 30 minutes in seconds
91+
moving_time: 1620, // 27 minutes in seconds
92+
average_heartrate: 165,
93+
max_heartrate: 190,
94+
kudos_count: 6,
95+
achievement_count: 1,
96+
athlete_count: 1,
97+
photo_count: 0,
98+
private: false,
99+
flagged: false
100+
};
101+
84102
describe('Strava Activity Mapping', () => {
85103
let t: Awaited<ReturnType<typeof createTestContext>>;
86104

@@ -246,6 +264,41 @@ describe('Strava Activity Mapping', () => {
246264
});
247265
});
248266

267+
it('should map HIIT activity to our format', async () => {
268+
const userId = await createTestUser(t);
269+
const challengeId = await createTestChallenge(t, userId);
270+
271+
const activityTypeId = await t.run(async (ctx) => {
272+
return await ctx.db.insert("activityTypes", {
273+
challengeId,
274+
name: 'HIIT',
275+
scoringConfig: {
276+
unit: 'minutes',
277+
pointsPerUnit: 5,
278+
basePoints: 25,
279+
},
280+
contributesToStreak: true,
281+
isNegative: false,
282+
createdAt: Date.now(),
283+
updatedAt: Date.now(),
284+
});
285+
});
286+
287+
const mapper = new StravaActivityMapper(challengeId, userId, fetchActivityTypes);
288+
const mapped = await mapper.mapActivity(stravaHIITActivity, activityTypeId);
289+
290+
expect(mapped.challengeId).toBe(challengeId);
291+
expect(mapped.activityTypeId).toBe(activityTypeId);
292+
expect(mapped.loggedDate).toBe('2024-03-15');
293+
expect(mapped.source).toBe('strava');
294+
expect(mapped.externalId).toBe('55443322');
295+
expect(mapped.metrics).toEqual({
296+
minutes: 30,
297+
average_heartrate: 165,
298+
max_heartrate: 190,
299+
});
300+
});
301+
249302
it('should handle activity type mapping based on sport type', async () => {
250303
const userId = await createTestUser(t);
251304
const challengeId = await createTestChallenge(t, userId);
@@ -286,6 +339,31 @@ describe('Strava Activity Mapping', () => {
286339
expect(cyclingActivityTypeId).toBe(cyclingTypeId);
287340
});
288341

342+
it('should detect HIIT activity type correctly', async () => {
343+
const userId = await createTestUser(t);
344+
const challengeId = await createTestChallenge(t, userId);
345+
346+
const hiitTypeId = await t.run(async (ctx) => {
347+
return await ctx.db.insert("activityTypes", {
348+
challengeId,
349+
name: 'HIIT',
350+
scoringConfig: { unit: 'minutes', pointsPerUnit: 5 },
351+
contributesToStreak: true,
352+
isNegative: false,
353+
createdAt: Date.now(),
354+
updatedAt: Date.now(),
355+
});
356+
});
357+
358+
const mapper = new StravaActivityMapper(challengeId, userId, fetchActivityTypes);
359+
360+
// Test automatic type detection for HIIT
361+
const hiitActivityTypeId = await mapper.detectActivityType(stravaHIITActivity);
362+
363+
// Should find the HIIT activity type
364+
expect(hiitActivityTypeId).toBe(hiitTypeId);
365+
});
366+
289367
it('should handle unknown activity types gracefully', async () => {
290368
const userId = await createTestUser(t);
291369
const challengeId = await createTestChallenge(t, userId);

0 commit comments

Comments
 (0)