mirror of
https://github.com/caoer/CodableFirebase.git
synced 2026-01-13 08:49:39 +08:00
Cover firestore types with tests
This commit is contained in:
@@ -428,8 +428,8 @@ class TestCodableFirebase: XCTestCase {
|
||||
// MARK: - Test Types
|
||||
/* FIXME: Import from %S/Inputs/Coding/SharedTypes.swift somehow. */
|
||||
|
||||
// MARK: - GeioPoint
|
||||
fileprivate struct Point: GeoPointType, Equatable {
|
||||
// MARK: - GeoPoint
|
||||
struct Point: GeoPointType, Equatable {
|
||||
let latitude: Double
|
||||
let longitude: Double
|
||||
|
||||
|
||||
@@ -109,6 +109,21 @@ class TestCodableFirestore: XCTestCase {
|
||||
_testRoundTrip(of: TopLevelWrapper(date), expected: ["value": date])
|
||||
}
|
||||
|
||||
// MARK: - GeoPoint & Document Reference
|
||||
func testEncodingGeoPoint() {
|
||||
let point = GeoPoint(latitude: 2, longitude: 2)
|
||||
let wrapper = TopLevelWrapper(point)
|
||||
XCTAssertEqual((try? FirestoreEncoder().encode(wrapper)) as NSDictionary?, ["value": point])
|
||||
XCTAssertEqual(try? FirestoreDecoder().decode(TopLevelWrapper<GeoPoint>.self, from: ["value": point]), wrapper)
|
||||
XCTAssertThrowsError(try FirestoreEncoder().encode(TopLevelWrapper(Point(latitude: 2, longitude: 2))))
|
||||
}
|
||||
|
||||
func testEncodingDocumentReference() {
|
||||
let val = TopLevelWrapper(DocumentReference())
|
||||
XCTAssertEqual((try? FirestoreEncoder().encode(val)) as NSDictionary?, ["value": val.value])
|
||||
XCTAssertEqual(try? FirestoreDecoder().decode(TopLevelWrapper<DocumentReference>.self, from: ["value": val.value]), val)
|
||||
}
|
||||
|
||||
private func _testEncodeFailure<T : Encodable>(of value: T) {
|
||||
do {
|
||||
let _ = try FirestoreEncoder().encode(value)
|
||||
@@ -164,3 +179,21 @@ func expectEqualPaths(_ lhs: [CodingKey], _ rhs: [CodingKey], _ prefix: String)
|
||||
XCTAssertEqual(key1.stringValue, key2.stringValue, "\(prefix) CodingKey.stringValue mismatch: \(type(of: key1))('\(key1.stringValue)') != \(type(of: key2))('\(key2.stringValue)')")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - GeioPoint
|
||||
fileprivate class GeoPoint: NSObject, GeoPointType {
|
||||
let latitude: Double
|
||||
let longitude: Double
|
||||
|
||||
required init(latitude: Double, longitude: Double) {
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
}
|
||||
|
||||
static func == (lhs: Point, rhs: Point) -> Bool {
|
||||
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ReferenceType
|
||||
fileprivate class DocumentReference: NSObject, DocumentReferenceType {}
|
||||
|
||||
Reference in New Issue
Block a user