friday-sdk
Version:
Official JavaScript/TypeScript SDK for the Friday API
165 lines (164 loc) • 6.8 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const dotenv = __importStar(require("dotenv"));
// Load environment variables
dotenv.config();
describe('FridayClient', () => {
let client;
beforeAll(() => {
if (!process.env.FRIDAY_API_KEY) {
throw new Error('FRIDAY_API_KEY is required in .env file');
}
client = new index_1.FridayClient({
apiKey: process.env.FRIDAY_API_KEY
});
});
// API Status Test
describe('get_status', () => {
test('should check API status', async () => {
const status = await client.get_status();
console.log('\nAPI Status:', status);
expect(status).toBeDefined();
expect(status).toHaveProperty('status');
});
});
// LinkedIn Profile Tests
describe('getProfile', () => {
const testProfileUrl = "https://www.linkedin.com/in/shlokparab/";
test('should fetch profile with default caching', async () => {
console.log('\nTesting cached profile fetch:');
const result = await client.getProfile({
profileUrl: testProfileUrl
});
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
expect(typeof result).toBe('object');
}, 60000); // 60 second timeout
test('should fetch profile with realtime=true', async () => {
console.log('\nTesting realtime profile fetch:');
const result = await client.getProfile({
profileUrl: testProfileUrl,
realtime: true
});
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
expect(typeof result).toBe('object');
}, 60000); // 60 second timeout
});
// Company Analysis Tests
describe('analyzeCompany', () => {
test('should analyze company from LinkedIn URL', async () => {
console.log('\nTesting company analysis:');
const result = await client.analyzeCompany("https://www.linkedin.com/company/raisegate/");
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
expect(typeof result).toBe('object');
}, 30000);
});
// Web Scraping Tests
describe('scrape', () => {
test('should scrape website with multiple formats', async () => {
console.log('\nTesting web scraping:');
const result = await client.scrape("https://fridaydata.tech", {
formats: ["html", "markdown", "links"]
});
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
expect(typeof result).toBe('object');
}, 30000);
});
// Web Crawling Tests
describe('crawl', () => {
test('should crawl website with specified options', async () => {
console.log('\nTesting web crawling:');
const result = await client.crawl("https://fridaydata.tech", {
formats: ["html", "markdown"],
maxPages: 2
});
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
expect(typeof result).toBe('object');
}, 30000);
});
// Search Tests - Currently Down
describe('search', () => {
test('should handle search endpoint being down gracefully', async () => {
console.log('\nTesting search (known to be down):');
try {
await client.search("AI startups in San Francisco", "US", 5);
}
catch (error) {
expect(error.message).toContain('404');
console.log('Search endpoint is down as expected:', error.message);
}
});
});
// Information Extraction Tests
describe('extract', () => {
test('should extract information without custom schema', async () => {
console.log('\nTesting extraction without schema:');
const result = await client.extract("https://fridaydata.tech", "Extract the main features and pricing information");
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
}, 30000);
test('should extract information with custom schema', async () => {
console.log('\nTesting extraction with schema:');
const customSchema = {
features: {
type: "array",
items: {
type: "object",
properties: {
name: { type: "string" },
description: { type: "string" }
}
}
},
pricing: {
type: "object",
properties: {
plans: { type: "array" },
currency: { type: "string" }
}
}
};
const result = await client.extract("https://fridaydata.tech", "Extract the main features and pricing information", customSchema);
console.log(JSON.stringify(result, null, 2));
expect(result).toBeDefined();
}, 30000);
});
});