77 getByCountry ,
88 has ,
99 ips ,
10+ random ,
1011} from "../src" ;
1112
1213test ( "exports the generated IP list" , ( ) => {
@@ -29,8 +30,23 @@ test("groups IPs by country", () => {
2930test ( "looks up IP membership and country" , ( ) => {
3031 assert . equal ( has ( "93.123.23.1" ) , true ) ;
3132 assert . equal ( has ( "127.0.0.1" ) , false ) ;
33+ assert . equal ( has ( 127001 ) , false ) ;
3234 assert . equal ( findCountry ( "118.174.25.251" ) , "Thailand" ) ;
3335 assert . equal ( findCountry ( "127.0.0.1" ) , undefined ) ;
36+ assert . equal ( findCountry ( null ) , undefined ) ;
37+ } ) ;
38+
39+ test ( "returns random IPs from all data or a country" , ( ) => {
40+ const originalRandom = Math . random ;
41+ Math . random = ( ) => 0 ;
42+
43+ try {
44+ assert . equal ( random ( ) , "93.123.23.1" ) ;
45+ assert . equal ( random ( "Bulgaria" ) , "93.123.23.1" ) ;
46+ assert . equal ( random ( "Unknown" ) , undefined ) ;
47+ } finally {
48+ Math . random = originalRandom ;
49+ }
3450} ) ;
3551
3652test ( "returns immutable data" , ( ) => {
@@ -41,3 +57,9 @@ test("returns immutable data", () => {
4157 ( byCountry . Bulgaria as string [ ] ) . push ( "127.0.0.1" ) ;
4258 } , TypeError ) ;
4359} ) ;
60+
61+ test ( "validates country input" , ( ) => {
62+ assert . throws ( ( ) => {
63+ getByCountry ( 123 as unknown as string ) ;
64+ } , TypeError ) ;
65+ } ) ;
0 commit comments