Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Nov 18, 2023
1 parent 787e463 commit 509d97b
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "australianFootball"
case .badminton:
return "badminton"
case .barre:
return "barre"
case .baseball:
return "baseball"
case .basketball:
Expand All @@ -44,10 +46,18 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "bowling"
case .boxing:
return "boxing"
case .cardioDance:
return "cardioDance"
case .climbing:
return "climbing"
case .cooldown:
return "coolDown"
case .coreTraining:
return "coreTraining"
case .cricket:
return "cricket"
case .crossCountrySkiing:
return "crossCountrySkiing"
case .crossTraining:
return "crossTraining"
case .curling:
Expand All @@ -58,6 +68,10 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "dance"

Check warning on line 68 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L68

Added line #L68 was not covered by tests
case .danceInspiredTraining:
return "danceInspiredTraining"

Check warning on line 70 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L70

Added line #L70 was not covered by tests
case .discSports:
return "discSports"
case .downhillSkiing:
return "downhillSkiing"
case .elliptical:
return "elliptical"
case .equestrianSports:
Expand All @@ -66,30 +80,50 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "fencing"
case .fishing:
return "fishing"
case .fitnessGaming:
return "fitnessGaming"
case .flexibility:
return "flexibility"
case .functionalStrengthTraining:
return "functionalStrengthTraining"
case .golf:
return "golf"
case .gymnastics:
return "gymnastics"
case .handCycling:
return "handCycling"
case .handball:
return "handball"
case .highIntensityIntervalTraining:
return "highIntensityIntervalTraining"
case .hiking:
return "hiking"
case .hockey:
return "hockey"
case .hunting:
return "hunting"
case .jumpRope:
return "jumpRope"
case .kickboxing:
return "kickboxing"
case .lacrosse:
return "lacrosse"
case .martialArts:
return "martialArts"
case .mindAndBody:
return "mindAndBody"
case .mixedCardio:
return "mixedCardio"
case .mixedMetabolicCardioTraining:
return "mixedMetabolicCardioTraining"

Check warning on line 118 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L118

Added line #L118 was not covered by tests
case .other:
return "other"
case .paddleSports:
return "paddleSports"
case .pickleball:
return "pickleball"
case .pilates:
return "pilates"
case .play:
return "play"
case .preparationAndRecovery:
Expand All @@ -106,28 +140,44 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "sailing"
case .skatingSports:
return "skatingSports"
case .snowboarding:
return "snowboarding"
case .snowSports:
return "snowSports"
case .soccer:
return "soccer"
case .socialDance:
return "socialDance"
case .softball:
return "softball"
case .squash:
return "squash"
case .stairClimbing:
return "stairClimbing"
case .stairs:
return "stairs"

Check warning on line 158 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L158

Added line #L158 was not covered by tests
case .stepTraining:
return "stepTraining"
case .surfingSports:
return "surfingSports"
case .swimBikeRun:
return "swimBikeRun"
case .swimming:
return "swimming"
case .tableTennis:
return "tableTennis"
case .taiChi:
return "taiChi"
case .tennis:
return "tennis"
case .trackAndField:
return "trackAndField"
case .traditionalStrengthTraining:
return "traditionalStrengthTraining"
case .transition:
return "transition"
case .underwaterDiving:
return "underwaterDiving"

Check warning on line 180 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L180

Added line #L180 was not covered by tests
case .volleyball:
return "volleyball"
case .walking:
Expand All @@ -138,64 +188,14 @@ extension HKWorkoutActivityType: HKWorkoutActivityTypeDescription {
return "waterPolo"
case .waterSports:
return "waterSports"
case .wheelchairRunPace:
return "wheelchairRunPace"
case .wheelchairWalkPace:
return "wheelchairWalkPace"
case .wrestling:
return "wrestling"
case .yoga:
return "yoga"
case .barre:
return "barre"
case .coreTraining:
return "coreTraining"
case .crossCountrySkiing:
return "crossCountrySkiing"
case .downhillSkiing:
return "downhillSkiing"
case .flexibility:
return "flexibility"
case .highIntensityIntervalTraining:
return "highIntensityIntervalTraining"
case .jumpRope:
return "jumpRope"
case .kickboxing:
return "kickboxing"
case .pilates:
return "pilates"
case .snowboarding:
return "snowboarding"
case .stairs:
return "stairs"
case .stepTraining:
return "stepTraining"
case .wheelchairWalkPace:
return "wheelchairWalkPace"
case .wheelchairRunPace:
return "wheelchairRunPace"
case .taiChi:
return "taiChi"
case .mixedCardio:
return "mixedCardio"
case .handCycling:
return "handCycling"
case .discSports:
return "discSports"
case .fitnessGaming:
return "fitnessGaming"
case .cardioDance:
return "cardioDance"
case .socialDance:
return "socialDance"
case .pickleball:
return "pickleball"
case .cooldown:
return "coolDown"
case .swimBikeRun:
return "swimBikeRun"
case .transition:
return "transition"
case .underwaterDiving:
return "underwaterDiving"
case .other:
return "other"
@unknown default:
throw HealthKitOnFHIRError.invalidValue

Check warning on line 200 in Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HealthKitOnFHIR/HealthKit Extensions/HKWorkoutActivityType+String.swift#L200

Added line #L200 was not covered by tests
}
Expand Down
105 changes: 96 additions & 9 deletions Tests/HealthKitOnFHIRTests/HKWorkoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,88 @@ class HKWorkoutTests: XCTestCase {
}
}

let supportedWorkoutActivityTypes: [HKWorkoutActivityType] = [
.americanFootball,
.archery,
.australianFootball,
.badminton,
.barre,
.baseball,
.basketball,
.bowling,
.boxing,
.cardioDance,
.climbing,
.cooldown,
.coreTraining,
.cricket,
.crossCountrySkiing,
.crossTraining,
.curling,
.cycling,
.discSports,
.downhillSkiing,
.elliptical,
.equestrianSports,
.fencing,
.fishing,
.fitnessGaming,
.flexibility,
.functionalStrengthTraining,
.golf,
.gymnastics,
.handCycling,
.handball,
.highIntensityIntervalTraining,
.hiking,
.hockey,
.hunting,
.jumpRope,
.kickboxing,
.lacrosse,
.martialArts,
.mindAndBody,
.mixedCardio,
.other,
.paddleSports,
.pickleball,
.pilates,
.play,
.preparationAndRecovery,
.racquetball,
.rowing,
.rugby,
.running,
.sailing,
.skatingSports,
.snowboarding,
.snowSports,
.soccer,
.socialDance,
.softball,
.squash,
.stairClimbing,
.stepTraining,
.surfingSports,
.swimBikeRun,
.swimming,
.tableTennis,
.taiChi,
.tennis,
.trackAndField,
.traditionalStrengthTraining,
.transition,
.volleyball,
.walking,
.waterFitness,
.waterPolo,
.waterSports,
.wheelchairRunPace,
.wheelchairWalkPace,
.wrestling,
.yoga
]

func createCodeableConcept(
code: String,
system: String
Expand All @@ -41,18 +123,23 @@ class HKWorkoutTests: XCTestCase {
)
}

func testSingleWorkout() throws {
func testHKWorkoutToObservation() throws {
// The HKWorkout initializers are deprecated as of iOS 17 in favor of using `HKWorkoutBuilder`, but there
// is currently no mechanism to use `HKWorkoutBuilder` inside unit tests without an authenticated
// `HKHealthStore`, so we use this approach.
let workoutSample = HKWorkout(
activityType: .americanFootball,
start: try startDate,
end: try endDate
)
for activityType in supportedWorkoutActivityTypes {
let workoutSample = HKWorkout(
activityType: activityType,
start: try startDate,
end: try endDate
)

let observation = try XCTUnwrap(workoutSample.resource.get(if: Observation.self))
let expectedValue = createCodeableConcept(code: "americanFootball", system: "http://developer.apple.com/documentation/healthkit")
XCTAssertEqual(observation.value, .codeableConcept(expectedValue))
let observation = try XCTUnwrap(workoutSample.resource.get(if: Observation.self))
let expectedValue = createCodeableConcept(
code: try activityType.workoutTypeDescription,
system: "http://developer.apple.com/documentation/healthkit"
)
XCTAssertEqual(observation.value, .codeableConcept(expectedValue))
}
}
}

0 comments on commit 509d97b

Please sign in to comment.