Skip to content

Commit

Permalink
fix(datastore): FlutterSerializedModel.extractJsonValue returns `.som…
Browse files Browse the repository at this point in the history
…e(nil)` instead of `nil` (#5370)
  • Loading branch information
Equartey authored Aug 26, 2024
1 parent 6a37755 commit 65afb4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,13 @@ class AmplifySerializedModelUnitTests: XCTestCase {
}
}
}

func test_extracts_some_nil() throws {
let output = try FlutterSerializedModelData.BlogWithNullSerializedModel.jsonValue(for: "post")

// This ensures if a property has a `null` json value, it gets returned as `.some(nil)`
// Per https://github.com/aws-amplify/amplify-swift/blob/cb80b91c38d99932af28df6be07633ee0563be08/Amplify/Categories/DataStore/Model/JSONHelper/JSONValueHolder.swift#L33-L34
XCTAssertNotNil(output)
XCTAssertNil(output!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ struct FlutterSerializedModelData {
"id": JSONValue.string("999"),
"name": JSONValue.string("blog name"),
], modelName: "Blog")
static var BlogWithNullSerializedModel: FlutterSerializedModel =
.init(map: [
"id": JSONValue.string("999"),
"name": JSONValue.string("blog name"),
"post": JSONValue.null,
], modelName: "Blog")
static var CommentSerializedModel: FlutterSerializedModel =
.init(map: [
"id": JSONValue.string("999"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct FlutterSerializedModel: Model, ModelIdentifiable, JSONValueHolder
case .string(let deserializedValue):
return deserializedValue
case .null:
return nil
return .some(nil)
}
}

Expand Down

0 comments on commit 65afb4d

Please sign in to comment.