UNPKG

ipgeo_sdk

Version:

A TypeScript SDK for interacting with the IPGeo API, providing fast and reliable geolocation services.

63 lines (62 loc) 3.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config({ path: '.env.local' }); const client_1 = require("./client"); describe('IPGeoSdk', () => { const apiKey = process.env.IPGEO_API_KEY; let client; beforeEach(() => { client = new client_1.IPGeoSdk({ apiKey }); }); it('should initialize with the provided API key', () => { expect(client).toBeInstanceOf(client_1.IPGeoSdk); }); it('should make a real API call and return data for getGeoData', async () => { var _a; const ip = (_a = process.env.IP_ADDRESS) !== null && _a !== void 0 ? _a : '8.8.8.8'; const result = await client.getGeoData(ip); console.log('API returned:', result); expect(result).toBeDefined(); return result; }); it('should throw a Zod error for an invalid IP address string', async () => { const invalidIp = 'not.an.ip'; await expect(client.getGeoData(invalidIp)).rejects.toThrow('Invalid IP address format'); }); it('should throw a Zod error for an valid IP address string but with extra spaces', async () => { const invalidIp = ' 8.8.8.8 '; await expect(client.getGeoData(invalidIp)).rejects.toThrow('Invalid IP address format'); }); it('should throw a Zod type error for a boolean as IP address', async () => { const invalidIp = true; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); it('should throw a Zod type error for a number as IP address', async () => { const invalidIp = 12345; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); it('should throw a Zod error for an empty string as IP address', async () => { const invalidIp = ''; await expect(client.getGeoData(invalidIp)).rejects.toThrow('Invalid IP address format'); }); it('should throw a Zod type error for null as IP address', async () => { const invalidIp = null; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); it('should throw a Zod type error for undefined as IP address', async () => { const invalidIp = undefined; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); it('should throw a Zod type error for an array as IP address', async () => { const invalidIp = ['8.8.8.8']; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); it('should throw a Zod type error for an object as IP address', async () => { const invalidIp = { ip: '8.8.8.8' }; await expect(client.getGeoData(invalidIp)).rejects.toThrow(/expected string|Invalid IP address format/); }); });