func TestFromRKConvertor(t *testing.T) { rkActivity := runkeeper.FitnessActivity{} rkActivity.Type = "Running" tim, _ := time.Parse("Mon, 2 Jan 2006 15:04:05", "Tue, 1 Mar 2011 07:00:00") rkActivity.StartTime = runkeeper.Time(tim) rkActivity.Duration = 10 rkActivity.Source = "RunKeeper" rkActivity.EntryMode = "API" rkActivity.HasMap = true rkActivity.Uri = "/activities/40" rkActivity.Path = make([]runkeeper.Path, 2) rkActivity.Path[0] = runkeeper.Path{1.0, 0.0, "gps", 10.0, 11.0} rkActivity.Path[1] = runkeeper.Path{2.0, 0.0, "gps", 15.0, 13.0} rkActivity.HeartRate = make([]runkeeper.HeartRate, 1) rkActivity.HeartRate[0] = runkeeper.HeartRate{1.0, 2} expectedActivity := dm.CreateActivity() expectedActivity.StartTime = int(tim.Unix()) expectedActivity.Duration = 10 expectedActivity.Type = "Running" activity := ConvertToActivity(&rkActivity) if !activity.ConsideredEqual(expectedActivity) || len(activity.GPS) != 2 || len(activity.HeartRate) != 1 { t.Error(fmt.Sprintf("activity %s should match result activity", activity)) } }
func ConvertToRkActivity(activity *dm.Activity) *runkeeper.FitnessActivityNew { rkActivity := runkeeper.CreateNewFitnessActivity(activity.Name, float64(activity.Duration)) rkActivity.Type = activity.Type //runkeeper only nows the following types: //Running, Cycling, Mountain Biking, Walking, //Hiking, Downhill Skiing, Cross-Country Skiing, //Snowboarding, Skating, Swimming, Wheelchair, Rowing, Elliptical, Other // //check if Type is one of these, otherwise Other. rkKnownTypes := map[string]string{ "Running": "Running", "Cycling": "Cycling", "Mountain Biking": "Mountain Biking", "Walking": "Walking", "Hiking": "Hiking", "Downhill Skiing": "Downhill Skiing", "Cross-Country Skiing": "Cross-Country Skiing", "Snowboarding": "Snowboarding", "Skating": "Skating", "Swimming": "Swimming", "Wheelchair": "Wheelchair", "Rowing": "Rowing", "Elliptical": "Elliptical", "Other": "Other"} _, ok := rkKnownTypes[activity.Type] if !ok { rkActivity.Type = "Other" } //runkeeper times are in local timezones, so covert back to the local time rkLocalLocation := time.FixedZone("rkZone", activity.UtcOffSet*60*60) rkActivity.StartTime = runkeeper.Time(time.Unix(int64(activity.StartTime), 0).In(rkLocalLocation)) rkActivity.Notes = activity.Name rkActivity.TotalDistance = activity.Distance rkActivity.AverageHeartRate = activity.AverageHeartRate rkActivity.TotalCalories = activity.Calories rkActivity.Source = activity.Source rkActivity.EntryMode = API rkActivity.Path = convertToPath(activity.GPS) rkActivity.HeartRate = convertToHR(activity.HeartRate) return rkActivity }
/* * Test a basic scenario from STV -> Runkeeper without any GPS or HR data. * Assumes activity in Local TZ */ func TestBasicSync(t *testing.T) { rkToken := "abcdef" stToken := "ghijkz" lastSeen := int(time.Now().Unix()) syncTask := CreateSyncTask(rkToken, stToken, lastSeen, "Prod") syncTask.Sync(stubStvImpl, stubRKImpl) expectedActivity := runkeeper.FitnessActivityNew{} expectedActivity.Type = "Running" expectedActivity.StartTime = runkeeper.Time(now) //RK actvitites are created in local time createdTimeString := time.Time(activtiesCreated[0].StartTime).Local().Format("Mon Jan 2 15:04:05 -0700 MST 2006") expectedTimeString := time.Time(expectedActivity.StartTime).Format("Mon Jan 2 15:04:05 -0700 MST 2006") if len(activtiesCreated) != 1 || createdTimeString != expectedTimeString { t.Error(fmt.Sprintf("%s is not %s", time.Time(activtiesCreated[0].StartTime).Local(), time.Time(expectedActivity.StartTime))) } }