UNPKG

friday-sdk

Version:

Official JavaScript/TypeScript SDK for the Friday API

125 lines (124 loc) 5.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); const dotenv_1 = __importDefault(require("dotenv")); // Set timeout for all tests jest.setTimeout(60000); describe('FridayClient', () => { let client; beforeEach(() => { // Load environment variables dotenv_1.default.config(); // Get API key from environment variable, with a default test key const apiKey = process.env.FRIDAY_API_KEY || 'test_key'; client = new index_1.FridayClient({ apiKey }); }); afterAll(done => { // Cleanup any pending handles done(); }); describe('getProfile', () => { it('should fetch and analyze a LinkedIn profile', () => __awaiter(void 0, void 0, void 0, function* () { const profile = yield client.getProfile('https://linkedin.com/in/yashpanditrao'); expect(profile).toBeDefined(); expect(profile).toMatchObject({ name: expect.any(String), title: expect.any(String), company: expect.any(String) }); }), 60000); }); describe('analyzeCompany', () => { it('should analyze a company based on LinkedIn URL', () => __awaiter(void 0, void 0, void 0, function* () { const analysis = yield client.analyzeCompany('https://linkedin.com/company/raisegate'); expect(analysis).toBeDefined(); expect(analysis).toMatchObject({ name: expect.any(String), description: expect.any(String), industry: expect.any(String) }); }), 60000); }); describe('scrape', () => { it('should scrape a website', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(2); try { const scraped = yield client.scrape('https://raisegate.com', { formats: ['html', 'markdown'] }); expect(scraped).toBeDefined(); expect(scraped).toMatchObject({ url: expect.any(String), content: expect.any(String) }); } catch (error) { console.warn('Warning: scrape test failed:', error.message); } })); }); describe('crawl', () => { it('should crawl a website', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(2); try { const crawled = yield client.crawl('https://raisegate.com', { formats: ['html'], maxPages: 2 }); expect(crawled).toBeDefined(); expect(crawled).toMatchObject({ urls: expect.any(Array), contents: expect.any(Array) }); } catch (error) { console.warn('Warning: crawl test failed:', error.message); } })); }); describe('search', () => { it('should perform a search', () => __awaiter(void 0, void 0, void 0, function* () { const results = yield client.search('fundraising platforms for startups', 'US', 5); expect(results).toBeDefined(); expect(typeof results).toBe('string'); }), 60000); }); describe('extract', () => { it('should extract information from a website', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(2); try { const extracted = yield client.extract('https://supabase.com', 'Extract the main features in json format'); expect(extracted).toBeDefined(); expect(typeof extracted).toBe('string'); } catch (error) { console.warn('Warning: extract test failed:', error.message); } })); }); describe('getStatus', () => { it('should get API status', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(2); try { const status = yield client.getStatus(); expect(status).toBeDefined(); expect(typeof status).toBe('boolean'); } catch (error) { console.warn('Warning: getStatus test failed:', error.message); } })); }); });