Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datastore): FlutterSerializedModel.extractJsonValue returns .some(nil) instead of nil #5370

Merged
merged 1 commit into from
Aug 26, 2024
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
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
Loading