File size: 828 Bytes
f132e93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import test from 'node:test';
import assert from 'node:assert/strict';
import { logRealConsoleApiError } from './apiLogger.ts';

test('logRealConsoleApiError executes and outputs formatted error diagnostic', () => {
  let loggedError = false;
  const originalError = console.error;
  console.error = (...args) => {
    loggedError = true;
  };

  try {
    logRealConsoleApiError({
      topic: 'Test API Error Topic',
      endpoint: 'https://router.huggingface.co/hf-inference/v1/chat/completions',
      model: 'mistralai/Devstral-2-123B-Instruct-2512',
      status: 401,
      statusText: 'Unauthorized',
      message: 'Invalid access token provided',
      rawResponse: '{"error": "Authorization header is invalid"}',
    });

    assert.equal(loggedError, true);
  } finally {
    console.error = originalError;
  }
});