Skip to content

Commit 6b9ef6b

Browse files
authored
fix: ParseGeoPoint longitude validation checks wrong variable (#1089)
1 parent c555bbe commit 6b9ef6b

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

packages/dart/lib/src/objects/parse_geo_point.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class ParseGeoPoint {
1212
'Latitude must be within the range (-90.0, 90.0).',
1313
),
1414
assert(
15-
latitude < 180,
15+
longitude < 180,
1616
'Longitude must be within the range (-180.0, 180.0).',
1717
),
1818
assert(
19-
latitude > -180,
19+
longitude > -180,
2020
'Longitude must be within the range (-180.0, 180.0).',
2121
);
2222

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import 'package:parse_server_sdk/parse_server_sdk.dart';
2+
import 'package:test/test.dart';
3+
4+
import '../../test_utils.dart';
5+
6+
void main() {
7+
setUpAll(() async {
8+
await initializeParse();
9+
});
10+
11+
group('ParseGeoPoint', () {
12+
group('constructor validation', () {
13+
test('should create a valid GeoPoint with default values', () {
14+
final geoPoint = ParseGeoPoint();
15+
expect(geoPoint.latitude, equals(0.0));
16+
expect(geoPoint.longitude, equals(0.0));
17+
});
18+
19+
test('should create a valid GeoPoint with valid coordinates', () {
20+
final geoPoint = ParseGeoPoint(latitude: 40.0, longitude: -74.0);
21+
expect(geoPoint.latitude, equals(40.0));
22+
expect(geoPoint.longitude, equals(-74.0));
23+
});
24+
25+
test('should create a valid GeoPoint with edge case values', () {
26+
// Test boundary values that should be valid (exclusive bounds)
27+
final geoPoint1 = ParseGeoPoint(latitude: 89.999, longitude: 179.999);
28+
expect(geoPoint1.latitude, equals(89.999));
29+
expect(geoPoint1.longitude, equals(179.999));
30+
31+
final geoPoint2 = ParseGeoPoint(latitude: -89.999, longitude: -179.999);
32+
expect(geoPoint2.latitude, equals(-89.999));
33+
expect(geoPoint2.longitude, equals(-179.999));
34+
});
35+
36+
test('should throw assertion error for latitude >= 90', () {
37+
expect(
38+
() => ParseGeoPoint(latitude: 90.0, longitude: 0.0),
39+
throwsA(isA<AssertionError>()),
40+
);
41+
42+
expect(
43+
() => ParseGeoPoint(latitude: 100.0, longitude: 0.0),
44+
throwsA(isA<AssertionError>()),
45+
);
46+
});
47+
48+
test('should throw assertion error for latitude <= -90', () {
49+
expect(
50+
() => ParseGeoPoint(latitude: -90.0, longitude: 0.0),
51+
throwsA(isA<AssertionError>()),
52+
);
53+
54+
expect(
55+
() => ParseGeoPoint(latitude: -100.0, longitude: 0.0),
56+
throwsA(isA<AssertionError>()),
57+
);
58+
});
59+
60+
test('should throw assertion error for longitude >= 180', () {
61+
expect(
62+
() => ParseGeoPoint(latitude: 0.0, longitude: 180.0),
63+
throwsA(isA<AssertionError>()),
64+
);
65+
66+
expect(
67+
() => ParseGeoPoint(latitude: 0.0, longitude: 200.0),
68+
throwsA(isA<AssertionError>()),
69+
);
70+
});
71+
72+
test('should throw assertion error for longitude <= -180', () {
73+
expect(
74+
() => ParseGeoPoint(latitude: 0.0, longitude: -180.0),
75+
throwsA(isA<AssertionError>()),
76+
);
77+
78+
expect(
79+
() => ParseGeoPoint(latitude: 0.0, longitude: -200.0),
80+
throwsA(isA<AssertionError>()),
81+
);
82+
});
83+
});
84+
85+
group('toJson', () {
86+
test('should return correct JSON representation', () {
87+
final geoPoint = ParseGeoPoint(latitude: 40.0, longitude: -74.0);
88+
final json = geoPoint.toJson();
89+
90+
expect(json['__type'], equals('GeoPoint'));
91+
expect(json['latitude'], equals(40.0));
92+
expect(json['longitude'], equals(-74.0));
93+
});
94+
});
95+
96+
group('toString', () {
97+
test('should return correct string representation', () {
98+
final geoPoint = ParseGeoPoint(latitude: 40.0, longitude: -74.0);
99+
expect(geoPoint.toString(), equals('latitude: 40.0, longitude: -74.0'));
100+
});
101+
});
102+
});
103+
}

0 commit comments

Comments
 (0)