File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,13 @@ let ipinfoWrapper: IPinfoWrapper;
77beforeEach ( ( ) => {
88 dotenv . config ( ) ;
99 const token = process . env . IPINFO_TOKEN || "" ;
10+
11+ if ( ! token ) {
12+ throw new Error (
13+ "Tests require a token in the IPINFO_TOKEN Environment Variable."
14+ ) ;
15+ }
16+
1017 ipinfoWrapper = new IPinfoWrapper ( token ) ;
1118} ) ;
1219
@@ -189,4 +196,20 @@ describe("IPinfoWrapper", () => {
189196 const ipinfo = new IPinfoWrapper ( "invalid-token" ) ;
190197 await expect ( ipinfo . lookupIp ( "1.2.3.4" ) ) . rejects . toThrow ( ) ;
191198 } ) ;
199+
200+ test ( "Error is thrown when response cannot be parsed" , async ( ) => {
201+ const baseUrlWithUnparseableResponse =
202+ "https://ipinfo.io/developers?path=" ;
203+ const ipinfo = new IPinfoWrapper (
204+ "token" ,
205+ baseUrlWithUnparseableResponse
206+ ) ;
207+ await expect ( ipinfo . lookupIp ( "1.2.3.4" ) ) . rejects . toThrow ( ) ;
208+
209+ const status = await ipinfo
210+ . lookupIp ( "1.2.3.4" )
211+ . then ( ( _ ) => "parseable" )
212+ . catch ( ( _ ) => "unparseable" ) ;
213+ expect ( status ) . toEqual ( "unparseable" ) ;
214+ } ) ;
192215} ) ;
You can’t perform that action at this time.
0 commit comments