Skip to content

Commit

Permalink
fix: don't crush on empty ipLocation field for new subs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Aug 5, 2024
1 parent bce4e71 commit 1aec7b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class FingerprintJSProExtendedResponse extends FingerprintJSProResponse {
super.json, super.requestId, super.confidence)
: visitorFound = json['visitorFound'],
ipAddress = json['ip'] ?? json['ipAddress'],
ipLocation =
IpLocation.fromJson(Map<String, dynamic>.from(json['ipLocation'])),
ipLocation = json['ipLocation'] != null
? IpLocation.fromJson(Map<String, dynamic>.from(json['ipLocation']))
: null,
osName = json['os'] ?? json['osName'],
osVersion = json['osVersion'],
device = json['device'],
Expand Down
12 changes: 10 additions & 2 deletions test/result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ void main() {
throwsA(isA<TypeError>()));
});

test('Check failed scenario with missed `ipLocation`', () {
jsonMock.remove("ipLocation");
test('Check failed scenario with missed `firstSeenAt`', () {
jsonMock.remove("firstSeenAt");
expect(
() => FingerprintJSProExtendedResponse.fromJson(
jsonMock, requestId, confidence),
Expand Down Expand Up @@ -148,5 +148,13 @@ void main() {
jsonMock, requestId, confidence);
expect(responseInstance.toJson(), extendedJsonMock);
});

test('Check empty ipLocation for a new customers', () {
jsonMock.remove('ipLocation');
extendedJsonMock['ipLocation'] = null;
final responseInstance = FingerprintJSProExtendedResponse.fromJson(
jsonMock, requestId, confidence);
expect(responseInstance.toJson(), extendedJsonMock);
});
});
}

0 comments on commit 1aec7b4

Please sign in to comment.