damien-rivet / JamfKit

A Jamf Classic communication framework written in Swift
MIT License
41 stars 1 forks source link

Rework PreciseDate JSON serialisation #52

Open damien-rivet opened 6 years ago

damien-rivet commented 6 years ago

Context

The PreciseDate class has been constructed to mimic the same behaviour as JSS payload when it comes to dates.

By acception a base key name, it allows the reconstruction of the 3 original keys for any date, like that:

{
    "example_date": "XXX",
    "example_date_epoch": 0,
    "example_date_utc": "XXX+0500"
}

If those keys were embedded in a single key it would have been much more simple to reconstruct the json before sending it to JSS.

An updated payload:

{
    "example_date": {
        "date": "XXX",
        "epoch": 0,
        "utc": "XXX+0500"
    }
}

Which in turn would improve the injection of each date in any JSON payload.

How it's currently done:

if let exampleDate = exampleDate {
    json.merge(exampleDate.toJSON()) { (_, new) in new }
}

Currently, this solution is problematic since the test coverage can't make it inside the block.

Issue

Find a better way of generating / injecting any date's JSON into another JSON payload.