@@ -2013,9 +2013,56 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
2013
2013
return
2014
2014
}
2015
2015
}
2016
- #endif
2017
2016
2018
- #if !os(Linux) && !os(Android)
2017
+ func testWhereKeyNearGeoPointWithinMilesNotSorted( ) throws {
2018
+ let expected : [ String : AnyCodable ] = [
2019
+ " yolo " : [ " $centerSphere " : [ " latitude " : 10 , " longitude " : 20 , " __type " : " GeoPoint " ] ,
2020
+ " $geoWithin " : 1
2021
+ ]
2022
+ ]
2023
+ let geoPoint = try ParseGeoPoint ( latitude: 10 , longitude: 20 )
2024
+ let constraint = withinMiles ( key: " yolo " ,
2025
+ geoPoint: geoPoint,
2026
+ distance: 3958.8 ,
2027
+ sorted: false )
2028
+ let query = GameScore . query ( constraint)
2029
+ let queryWhere = query. `where`
2030
+
2031
+ do {
2032
+ let encoded = try ParseCoding . jsonEncoder ( ) . encode ( queryWhere)
2033
+ let decodedDictionary = try JSONDecoder ( ) . decode ( [ String : AnyCodable ] . self, from: encoded)
2034
+ XCTAssertEqual ( expected. keys, decodedDictionary. keys)
2035
+
2036
+ guard let expectedValues = expected. values. first? . value as? [ String : Any ] ,
2037
+ let expectedNear = expectedValues [ " $centerSphere " ] as? [ String : Any ] ,
2038
+ let expectedLongitude = expectedNear [ " longitude " ] as? Int ,
2039
+ let expectedLatitude = expectedNear [ " latitude " ] as? Int ,
2040
+ let expectedType = expectedNear [ " __type " ] as? String ,
2041
+ let expectedDistance = expectedValues [ " $geoWithin " ] as? Int else {
2042
+ XCTFail ( " Should have casted " )
2043
+ return
2044
+ }
2045
+
2046
+ guard let decodedValues = decodedDictionary. values. first? . value as? [ String : Any ] ,
2047
+ let decodedNear = decodedValues [ " $centerSphere " ] as? [ String : Any ] ,
2048
+ let decodedLongitude = decodedNear [ " longitude " ] as? Int ,
2049
+ let decodedLatitude = decodedNear [ " latitude " ] as? Int ,
2050
+ let decodedType = decodedNear [ " __type " ] as? String ,
2051
+ let decodedDistance = decodedValues [ " $geoWithin " ] as? Int else {
2052
+ XCTFail ( " Should have casted " )
2053
+ return
2054
+ }
2055
+ XCTAssertEqual ( expectedLongitude, decodedLongitude)
2056
+ XCTAssertEqual ( expectedLatitude, decodedLatitude)
2057
+ XCTAssertEqual ( expectedType, decodedType)
2058
+ XCTAssertEqual ( expectedDistance, decodedDistance)
2059
+
2060
+ } catch {
2061
+ XCTFail ( error. localizedDescription)
2062
+ return
2063
+ }
2064
+ }
2065
+
2019
2066
func testWhereKeyNearGeoPointWithinKilometers( ) throws {
2020
2067
let expected : [ String : AnyCodable ] = [
2021
2068
" yolo " : [ " $nearSphere " : [ " latitude " : 10 , " longitude " : 20 , " __type " : " GeoPoint " ] ,
@@ -2062,6 +2109,55 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
2062
2109
}
2063
2110
}
2064
2111
2112
+ func testWhereKeyNearGeoPointWithinKilometersNotSorted( ) throws {
2113
+ let expected : [ String : AnyCodable ] = [
2114
+ " yolo " : [ " $centerSphere " : [ " latitude " : 10 , " longitude " : 20 , " __type " : " GeoPoint " ] ,
2115
+ " $geoWithin " : 1
2116
+ ]
2117
+ ]
2118
+ let geoPoint = try ParseGeoPoint ( latitude: 10 , longitude: 20 )
2119
+ let constraint = withinKilometers ( key: " yolo " ,
2120
+ geoPoint: geoPoint,
2121
+ distance: 6371.0 ,
2122
+ sorted: false )
2123
+ let query = GameScore . query ( constraint)
2124
+ let queryWhere = query. `where`
2125
+
2126
+ do {
2127
+ let encoded = try ParseCoding . jsonEncoder ( ) . encode ( queryWhere)
2128
+ let decodedDictionary = try JSONDecoder ( ) . decode ( [ String : AnyCodable ] . self, from: encoded)
2129
+ XCTAssertEqual ( expected. keys, decodedDictionary. keys)
2130
+
2131
+ guard let expectedValues = expected. values. first? . value as? [ String : Any ] ,
2132
+ let expectedNear = expectedValues [ " $centerSphere " ] as? [ String : Any ] ,
2133
+ let expectedLongitude = expectedNear [ " longitude " ] as? Int ,
2134
+ let expectedLatitude = expectedNear [ " latitude " ] as? Int ,
2135
+ let expectedType = expectedNear [ " __type " ] as? String ,
2136
+ let expectedDistance = expectedValues [ " $geoWithin " ] as? Int else {
2137
+ XCTFail ( " Should have casted " )
2138
+ return
2139
+ }
2140
+
2141
+ guard let decodedValues = decodedDictionary. values. first? . value as? [ String : Any ] ,
2142
+ let decodedNear = decodedValues [ " $centerSphere " ] as? [ String : Any ] ,
2143
+ let decodedLongitude = decodedNear [ " longitude " ] as? Int ,
2144
+ let decodedLatitude = decodedNear [ " latitude " ] as? Int ,
2145
+ let decodedType = decodedNear [ " __type " ] as? String ,
2146
+ let decodedDistance = decodedValues [ " $geoWithin " ] as? Int else {
2147
+ XCTFail ( " Should have casted " )
2148
+ return
2149
+ }
2150
+ XCTAssertEqual ( expectedLongitude, decodedLongitude)
2151
+ XCTAssertEqual ( expectedLatitude, decodedLatitude)
2152
+ XCTAssertEqual ( expectedType, decodedType)
2153
+ XCTAssertEqual ( expectedDistance, decodedDistance)
2154
+
2155
+ } catch {
2156
+ XCTFail ( error. localizedDescription)
2157
+ return
2158
+ }
2159
+ }
2160
+
2065
2161
func testWhereKeyNearGeoPointWithinRadians( ) throws {
2066
2162
let expected : [ String : AnyCodable ] = [
2067
2163
" yolo " : [ " $nearSphere " : [ " latitude " : 10 , " longitude " : 20 , " __type " : " GeoPoint " ] ,
0 commit comments