Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/NightscoutKit/Models/ProfileSet.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,15 +127,17 @@ public class ProfileSet {
public let store: ProfileStore
public let settings: LoopSettings
public let syncIdentifier: String

public init(startDate: Date, units: String, enteredBy: String, defaultProfile: String, store: ProfileStore, settings: LoopSettings, syncIdentifier: String) {
public let isAPNSProduction: Bool?

public init(startDate: Date, units: String, enteredBy: String, defaultProfile: String, store: ProfileStore, settings: LoopSettings, syncIdentifier: String, isAPNSProduction: Bool? = nil) {
self.startDate = startDate
self.units = units
self.enteredBy = enteredBy
self.defaultProfile = defaultProfile
self.store = store
self.settings = settings
self.syncIdentifier = syncIdentifier
self.isAPNSProduction = isAPNSProduction
}

public var dictionaryRepresentation: [String: Any] {
Expand All@@ -145,7 +147,7 @@ public class ProfileSet {
let dictProfiles = Dictionary(uniqueKeysWithValues:
store.map { key, value in (key, value.dictionaryRepresentation) })

let rval : [String: Any] = [
var rval : [String: Any] = [
"defaultProfile": defaultProfile,
"startDate": dateFormatter.string(from: startDate),
"mills": mills,
Expand All@@ -154,7 +156,11 @@ public class ProfileSet {
"loopSettings": settings.dictionaryRepresentation,
"store": dictProfiles
]


if let isAPNSProduction = isAPNSProduction {
rval["isAPNSProduction"] = isAPNSProduction
}

return rval
}

Expand All@@ -180,5 +186,6 @@ public class ProfileSet {
self.store = storeRaw.compactMapValues { Profile(rawValue: $0) }
self.settings = settings
self.syncIdentifier = syncIdentifier
self.isAPNSProduction = rawValue["isAPNSProduction"] as? Bool
}
}
17 changes: 17 additions & 0 deletions Tests/NightscoutKitTests/NightscoutKitTests.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,4 +18,21 @@ final class NightscoutKitTests: XCTestCase {

XCTAssertEqual("ETC/GMT+5", json["timezone"] as? String)
}

private func makeProfileSet(isAPNSProduction: Bool?) -> ProfileSet {
let timeZone = TimeZone(secondsFromGMT: 0)!
let schedule = [ProfileSet.ScheduleItem(offset: .hours(0), value: 1)]
let profile = ProfileSet.Profile(timezone: timeZone, dia: .hours(6), sensitivity: schedule, carbratio: schedule, basal: schedule, targetLow: schedule, targetHigh: schedule, units: "mg/dL")
let settings = LoopSettings(dosingEnabled: true, overridePresets: [], scheduleOverride: nil, minimumBGGuard: nil, preMealTargetRange: nil, maximumBasalRatePerHour: nil, maximumBolus: nil, deviceToken: "token", bundleIdentifier: "com.example.loop", dosingStrategy: "automaticBolus")
return ProfileSet(startDate: Date(), units: "mg/dL", enteredBy: "Loop", defaultProfile: "Default", store: ["Default": profile], settings: settings, syncIdentifier: "sync", isAPNSProduction: isAPNSProduction)
}

func testAPNSProductionEnvironmentIsSerializedAtTopLevel() {
XCTAssertEqual(true, makeProfileSet(isAPNSProduction: true).dictionaryRepresentation["isAPNSProduction"] as? Bool)
XCTAssertEqual(false, makeProfileSet(isAPNSProduction: false).dictionaryRepresentation["isAPNSProduction"] as? Bool)
}

func testAPNSProductionEnvironmentOmittedWhenUnset() {
XCTAssertNil(makeProfileSet(isAPNSProduction: nil).dictionaryRepresentation["isAPNSProduction"])
}
}