Преглед изворни кода

Merge pull request #435 from kingst/make-profile-testtarget-key-update

Fix incorrect output key for makeProfile
Deniz Cengiz пре 1 година
родитељ
комит
4717c6ce36

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/Models/ComputedBGTargets.swift

@@ -18,7 +18,7 @@ extension ComputedBGTargetEntry {
         case offset
         case maxBg = "max_bg"
         case minBg = "min_bg"
-        case temptargetSet = "temptarget_set"
+        case temptargetSet
     }
 }
 

+ 61 - 0
TrioTests/OpenAPSSwiftTests/ProfileJavascriptTests.swift

@@ -275,4 +275,65 @@ struct ProfileGeneratorTests {
 
         #expect(profile.model == "554")
     }
+
+    @Test("Profile should use temptargetSet key in output json") func testTempTargetSetKey() async throws {
+        var inputs = createBaseInputs()
+        inputs.7 = "\"554\"\n"
+        let now = Date()
+        let tempTargets = [
+            TempTarget(
+                name: nil,
+                createdAt: now - 1.hoursToSeconds,
+                targetTop: 100,
+                targetBottom: 80,
+                duration: 120,
+                enteredBy: nil,
+                reason: nil,
+                isPreset: nil,
+                enabled: nil,
+                halfBasalTarget: nil
+            )
+        ]
+
+        let openAps = OpenAPS(storage: BaseFileStorage(), tddStorage: MockTDDStorage())
+        let jsResult = await openAps.makeProfileJavascript(
+            preferences: inputs.4,
+            pumpSettings: inputs.0,
+            bgTargets: inputs.1,
+            basalProfile: inputs.2,
+            isf: inputs.3,
+            carbRatio: inputs.5,
+            tempTargets: tempTargets,
+            model: inputs.7,
+            autotune: RawJSON.null,
+            trioSettings: inputs.8
+        )
+
+        let swiftResult = OpenAPSSwift.makeProfile(
+            preferences: inputs.4,
+            pumpSettings: inputs.0,
+            bgTargets: inputs.1,
+            basalProfile: inputs.2,
+            isf: inputs.3,
+            carbRatio: inputs.5,
+            tempTargets: tempTargets,
+            model: inputs.7,
+            trioSettings: inputs.8
+        )
+
+        let comparison = JSONCompare.createComparison(
+            function: .makeProfile,
+            swift: swiftResult,
+            swiftDuration: 1.0,
+            javascript: jsResult,
+            javascriptDuration: 1.0,
+            iobInputs: nil
+        )
+
+        if comparison.resultType == .valueDifference {
+            print(comparison.differences!.prettyPrintedJSON!)
+        }
+
+        #expect(comparison.resultType == .matching)
+    }
 }