@@ -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+
84102describe ( '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