File tree Expand file tree Collapse file tree 4 files changed +38
-6
lines changed
Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Original file line number Diff line number Diff line change 1+ import cloneDeep = require( 'lodash.clonedeep' ) ;
2+ import * as insights from '../../../fixtures/insights.json' ;
3+ import Insights from './insights' ;
4+
5+ describe ( 'Insights()' , ( ) => {
6+ it ( 'handles empty country responses' , ( ) => {
7+ let input = cloneDeep ( insights ) as any ;
8+ input = input . response . full ;
9+ delete input . ip_address . country ;
10+
11+ const model = new Insights ( input ) ;
12+
13+ expect ( model . ipAddress . country . isHighRisk ) . toBeUndefined ( ) ;
14+ } ) ;
15+
16+ it ( 'handles empty location responses' , ( ) => {
17+ let input = cloneDeep ( insights ) as any ;
18+ input = input . response . full ;
19+ delete input . ip_address . location ;
20+
21+ const model = new Insights ( input ) ;
22+
23+ expect ( model . ipAddress . location . localTime ) . toBeUndefined ( ) ;
24+ } ) ;
25+ } ) ;
Original file line number Diff line number Diff line change @@ -45,8 +45,15 @@ export default class Insights extends Score {
4545 response : webRecords . InsightsResponse
4646 ) : records . IpAddress {
4747 const insights = new GeoInsights ( response . ip_address ) as records . IpAddress ;
48- insights . country . isHighRisk = response . ip_address . country . is_high_risk ;
49- insights . location . localTime = response . ip_address . location . local_time ;
48+
49+ insights . country . isHighRisk = response . ip_address . country
50+ ? response . ip_address . country . is_high_risk
51+ : undefined ;
52+
53+ insights . location . localTime = response . ip_address . location
54+ ? response . ip_address . location . local_time
55+ : undefined ;
56+
5057 insights . risk = response . ip_address . risk ;
5158
5259 delete insights . maxmind ;
Original file line number Diff line number Diff line change @@ -16,11 +16,11 @@ export interface GeoIPCountry extends CountryRecord {
1616 * @category Deprecated
1717 * @deprecated
1818 */
19- isHighRisk : boolean ;
19+ isHighRisk ? : boolean ;
2020}
2121
2222export interface GeoIPLocation extends LocationRecord {
23- localTime : string ;
23+ localTime ? : string ;
2424}
2525
2626export interface IpAddress extends Insights {
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ export interface GeoIPLocation extends LocationRecord {
1414
1515export interface IpAddress extends CityResponse {
1616 readonly risk : number ;
17- readonly country : GeoIPCountry ;
18- readonly location : GeoIPLocation ;
17+ readonly country ? : GeoIPCountry ;
18+ readonly location ? : GeoIPLocation ;
1919}
2020
2121export interface CreditCardIssuer {
You can’t perform that action at this time.
0 commit comments