File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed
Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ describe('Insights()', () => {
1010
1111 const model = new Insights ( input ) ;
1212
13- expect ( model . ipAddress . country ) . toBeUndefined ( ) ;
13+ expect ( model . ipAddress ? .country ) . toBeUndefined ( ) ;
1414 } ) ;
1515
1616 it ( 'handles empty location responses' , ( ) => {
@@ -20,7 +20,17 @@ describe('Insights()', () => {
2020
2121 const model = new Insights ( input ) ;
2222
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 ( ) ;
2434 } ) ;
2535
2636 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 {
2828 /**
2929 * An object containing GeoIP2 and minFraud Insights information about the IP address.
3030 */
31- public readonly ipAddress : records . IpAddress ;
31+ public readonly ipAddress ? : records . IpAddress ;
3232 /**
3333 * An object containing minFraud data related to the shipping address used in the transaction.
3434 */
@@ -65,7 +65,11 @@ export default class Insights extends Score {
6565
6666 private getIpAddress (
6767 response : webRecords . InsightsResponse
68- ) : records . IpAddress {
68+ ) : records . IpAddress | undefined {
69+ if ( ! response . ip_address ) {
70+ return undefined ;
71+ }
72+
6973 const insights = new GeoInsights ( response . ip_address ) as records . IpAddress ;
7074
7175 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 {
2020 /**
2121 * An object containing information about the IP address's risk.
2222 */
23- public readonly ipAddress : records . ScoreIpAddress ;
23+ public readonly ipAddress ? : records . ScoreIpAddress ;
2424 /**
2525 * The approximate number of queries remaining for this service before your
2626 * account runs out of funds.
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ export interface ScoreResponse {
146146 readonly disposition ?: DispositionWebRecord ;
147147 readonly funds_remaining : number ;
148148 readonly id : string ;
149- readonly ip_address : ScoreIpAddress ;
149+ readonly ip_address ? : ScoreIpAddress ;
150150 readonly queries_remaining : number ;
151151 readonly risk_score : number ;
152152 readonly warnings ?: Warning [ ] ;
You can’t perform that action at this time.
0 commit comments