import Foundation import Testing @testable import HUDKit // What a `Choice` sends: its call's input with the value chosen wherever // `{"$on": true}` stands, and the time wherever `{"$now": true}` does, the // rest as the server resolved it. @Suite struct Choosing { @Test func theValueChosenGoesWhereItsMarkIs() { let input: JSON = [ "preference": [ "$type": "social.grain.actor.defs#notificationsPref", "favorites": ["push": true, "inApp": false, "from": ["$on": true]], "follows": ["push": true, "inApp": true, "from": "all"], "at": ["$now": true], "list": [["$on": true], ["$on": true, "x": 1]], ] ] let now = Date(timeIntervalSince1970: 0) let sent = ResolvedChoice.stamped(input, on: "follows", now: now) #expect(sent["preference"]?["favorites"] == ["push": true, "inApp": false, "from": "follows"]) #expect(sent["preference"]?["follows"] == ["push": true, "inApp": true, "from": "all"]) #expect(sent["preference"]?["at"] == .string(Format.iso(now))) // Only a mark alone is filled. #expect(sent["preference"]?["list"] == ["follows", ["$on": true, "x": 1]]) } }