OverviewFilesCommitsIssuesDocsReleasesPeers

ollama_semantic_function_calling / ollamatools-new / keet / node_modules / @holepunchto / keet-link-preview / test.js

65 lines · javascript ref:
import test from 'brittle';
import getLinkPreview from './index.js';

test('fetch link preview for a valid Chinese news URL', async (t) => {
  const url = 'https://tw.stock.yahoo.com/news/%E9%80%80%E4%BC%91%E6%83%B3%E6%9C%88%E9%A0%984%E8%90%AC-%E5%8B%9E%E4%BF%9D%E5%8A%A0%E5%8B%9E%E9%80%80%E6%BB%BF%E8%B6%B3-3%E6%A2%9D%E4%BB%B6-%E5%B0%B1%E7%A9%A9%E4%BA%86-%E5%B0%88%E5%AE%B6%E6%8F%90%E9%86%92-151100770.html';
  const result = await getLinkPreview(url);
  
  t.ok(result && typeof result === 'object', 'Result should be an object');
  t.ok(result.url, 'Result should contain a valid URL');
  t.ok(result.title, 'Result should contain a valid title');
  t.ok(result.name, 'Result should contain a valid site name');
  t.ok(result.description, 'Result should contain a valid description');
  t.ok(result.favicon, 'Result should contain a valid favicon');
  t.is(
    result.title, 
    '退休想月領4萬!勞保加勞退滿足「3條件」就穩了 專家提醒「這操作」最關鍵', 
    'Title should exactly match expected Chinese title'
  );
});

test('fetch link preview for a valid English news URL', async (t) => {
  const url = 'https://www.yahoo.com/news/finance/news/openai-ceo-sam-altman-says-202110800.html';
  const result = await getLinkPreview(url);
  
  t.ok(result && typeof result === 'object', 'Result should be an object');
  t.ok(result.url, 'Result should contain a valid URL');
  t.ok(result.title, 'Result should contain a valid title');
  t.ok(result.name, 'Result should contain a valid site name');
  t.ok(result.description, 'Result should contain a valid description');
  t.ok(result.favicon, 'Result should contain a valid favicon');
  t.is(
    result.description,
    'OpenAI CEO Sam Altman said that the company was forced to stagger the rollout of its newest model, GPT-4.5, because OpenAI is "out of GPUs."  In a post on X, Altman said that GPT-4.5, which he described as "giant" and "expensive," will require "tens of thousands" more GPUs before additional ChatGPT users can gain access.  Perhaps in part due to its enormous size, GPT-4.5 is wildly expensive.',
    'Description should exactly match expected English text'
  );
});

test('fetch link preview for a valid Chinese news URL', async (t) => {
    const url = 'https://tw.stock.yahoo.com/news/%E9%80%80%E4%BC%91%E6%83%B3%E6%9C%88%E9%A0%984%E8%90%AC-%E5%8B%9E%E4%BF%9D%E5%8A%A0%E5%8B%9E%E9%80%80%E6%BB%BF%E8%B6%B3-3%E6%A2%9D%E4%BB%B6-%E5%B0%B1%E7%A9%A9%E4%BA%86-%E5%B0%88%E5%AE%B6%E6%8F%90%E9%86%92-151100770.html';
    const result = await getLinkPreview(url);
    
    t.ok(result && typeof result === 'object', 'Result should be an object');
    t.ok(result.url, 'Result should contain a valid URL');
    t.ok(result.title, 'Result should contain a valid title');
    t.ok(result.name, 'Result should contain a valid site name');
    t.ok(result.description, 'Result should contain a valid description');
    t.ok(result.favicon, 'Result should contain a valid favicon');
    t.is(
      result.title, 
      '退休想月領4萬!勞保加勞退滿足「3條件」就穩了 專家提醒「這操作」最關鍵', 
      'Title should exactly match expected Chinese title'
    );
  });
  
test('fetch link preview for an invalid site', async (t) => {
    const url = 'http://www.invalidurlll.com/';
    const result = await getLinkPreview(url);
    t.is(result, null, 'Invalid URL should return null');
  });

  test('fetch link preview for an empty URL', async (t) => {
    const url = '';
    const result = await getLinkPreview(url);
    t.is(result, null, 'Invalid URL should return null');
  });