File tree 4 files changed +20
-6
lines changed
4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ describe('Insights()', () => {
10
10
11
11
const model = new Insights ( input ) ;
12
12
13
- expect ( model . ipAddress . country ) . toBeUndefined ( ) ;
13
+ expect ( model . ipAddress ? .country ) . toBeUndefined ( ) ;
14
14
} ) ;
15
15
16
16
it ( 'handles empty location responses' , ( ) => {
@@ -20,7 +20,17 @@ describe('Insights()', () => {
20
20
21
21
const model = new Insights ( input ) ;
22
22
23
- expect ( model . ipAddress . location ) . toBeUndefined ( ) ;
23
+ expect ( model . ipAddress ?. location ) . toBeUndefined ( ) ;
24
+ } ) ;
25
+
26
+ it ( 'handles empty IP address responses' , ( ) => {
27
+ let input = cloneDeep ( insights ) as any ;
28
+ input = input . response . full ;
29
+ delete input . ip_address ;
30
+
31
+ const model = new Insights ( input ) ;
32
+
33
+ expect ( model . ipAddress ) . toBeUndefined ( ) ;
24
34
} ) ;
25
35
26
36
it ( 'allows /email/domain/first_seen to be accessed' , ( ) => {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export default class Insights extends Score {
28
28
/**
29
29
* An object containing GeoIP2 and minFraud Insights information about the IP address.
30
30
*/
31
- public readonly ipAddress : records . IpAddress ;
31
+ public readonly ipAddress ? : records . IpAddress ;
32
32
/**
33
33
* An object containing minFraud data related to the shipping address used in the transaction.
34
34
*/
@@ -65,7 +65,11 @@ export default class Insights extends Score {
65
65
66
66
private getIpAddress (
67
67
response : webRecords . InsightsResponse
68
- ) : records . IpAddress {
68
+ ) : records . IpAddress | undefined {
69
+ if ( ! response . ip_address ) {
70
+ return undefined ;
71
+ }
72
+
69
73
const insights = new GeoInsights ( response . ip_address ) as records . IpAddress ;
70
74
71
75
if ( insights . country && response . ip_address . country ) {
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export default class Score {
20
20
/**
21
21
* An object containing information about the IP address's risk.
22
22
*/
23
- public readonly ipAddress : records . ScoreIpAddress ;
23
+ public readonly ipAddress ? : records . ScoreIpAddress ;
24
24
/**
25
25
* The approximate number of queries remaining for this service before your
26
26
* account runs out of funds.
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ export interface ScoreResponse {
146
146
readonly disposition ?: DispositionWebRecord ;
147
147
readonly funds_remaining : number ;
148
148
readonly id : string ;
149
- readonly ip_address : ScoreIpAddress ;
149
+ readonly ip_address ? : ScoreIpAddress ;
150
150
readonly queries_remaining : number ;
151
151
readonly risk_score : number ;
152
152
readonly warnings ?: Warning [ ] ;
You can’t perform that action at this time.
0 commit comments