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

Require explicit typing for DocumentSnapshot decoding. DocumentReference decoding. #9101

Merged
Prev Previous commit
Next Next commit
Updated CodableIntegrationTests to match updated API
  • Loading branch information
mortenbekditlevsen committed Feb 18, 2022
commit 848f5e271e7fcc4f3c7fd3a6b9ba8cd2113d7006
34 changes: 17 additions & 17 deletions Firestore/Swift/Tests/Integration/CodableIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

let readAfterWrite = try readDocument(forRef: docToWrite).data(as: Model.self)

XCTAssertEqual(readAfterWrite!, model, "Failed with flavor \(flavor)")
XCTAssertEqual(readAfterWrite, model, "Failed with flavor \(flavor)")
}
}

Expand All @@ -113,8 +113,8 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

let decoded = try readDocument(forRef: docToWrite).data(as: Model.self)

XCTAssertNotNil(decoded?.ts, "Failed with flavor \(flavor)")
if let ts = decoded?.ts {
XCTAssertNotNil(decoded.ts, "Failed with flavor \(flavor)")
if let ts = decoded.ts {
XCTAssertGreaterThan(ts.seconds, 1_500_000_000, "Failed with flavor \(flavor)")
} else {
XCTFail("Expect server timestamp is set, but getting .pending")
Expand Down Expand Up @@ -145,17 +145,17 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

let snapshot = readDocument(forRef: docToWrite)
var decoded = try snapshot.data(as: Model.self, with: .none)
XCTAssertNil(decoded?.ts)
XCTAssertNil(decoded.ts)

decoded = try snapshot.data(as: Model.self, with: .estimate)
XCTAssertNotNil(decoded?.ts)
XCTAssertNotNil(decoded?.ts?.seconds)
XCTAssertGreaterThanOrEqual(decoded!.ts!.seconds, now)
XCTAssertNotNil(decoded.ts)
XCTAssertNotNil(decoded.ts?.seconds)
XCTAssertGreaterThanOrEqual(decoded.ts!.seconds, now)

decoded = try snapshot.data(as: Model.self, with: .previous)
XCTAssertNotNil(decoded?.ts)
XCTAssertNotNil(decoded?.ts?.seconds)
XCTAssertEqual(decoded!.ts!.seconds, pastTimestamp.seconds)
XCTAssertNotNil(decoded.ts)
XCTAssertNotNil(decoded.ts?.seconds)
XCTAssertEqual(decoded.ts!.seconds, pastTimestamp.seconds)

enableNetwork()
awaitExpectations()
Expand Down Expand Up @@ -230,7 +230,7 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

// Decoded result has "docId" auto-populated.
let decoded = try readDocument(forRef: docToWrite).data(as: Model.self)
XCTAssertEqual(decoded!, Model(name: "name", docId: docToWrite))
XCTAssertEqual(decoded, Model(name: "name", docId: docToWrite))
}

func testSelfDocumentIDWithCustomCodable() throws {
Expand Down Expand Up @@ -277,7 +277,7 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

// Decoded result has "docId" auto-populated.
let decoded = try readDocument(forRef: docToWrite).data(as: Model.self)
XCTAssertEqual(decoded!, Model(name: "name", docId: docToWrite))
XCTAssertEqual(decoded, Model(name: "name", docId: docToWrite))
}

func testSetThenMerge() throws {
Expand All @@ -298,18 +298,18 @@ class CodableIntegrationTests: FSTIntegrationTestCase {

var readAfterUpdate = try readDocument(forRef: docToWrite).data(as: Model.self)

XCTAssertEqual(readAfterUpdate!, Model(name: "test",
age: 43, hobby: "No"), "Failed with flavor \(flavor)")
XCTAssertEqual(readAfterUpdate, Model(name: "test",
age: 43, hobby: "No"), "Failed with flavor \(flavor)")

let newUpdate = Model(name: "xxxx", age: 10, hobby: "Play")
// Note 'name' is not updated.
try setData(from: newUpdate, forDocument: docToWrite, withFlavor: flavor,
mergeFields: ["age", FieldPath(["hobby"])])

readAfterUpdate = try readDocument(forRef: docToWrite).data(as: Model.self)
XCTAssertEqual(readAfterUpdate!, Model(name: "test",
age: 10,
hobby: "Play"), "Failed with flavor \(flavor)")
XCTAssertEqual(readAfterUpdate, Model(name: "test",
age: 10,
hobby: "Play"), "Failed with flavor \(flavor)")
}
}

Expand Down