openai-node

Форк
0
/
stringifyQuery.test.ts 
26 строк · 890.0 Байт
1
import { APIClient } from 'openai/core';
2

3
const { stringifyQuery } = APIClient.prototype as any;
4

5
describe('APIClient.stringifyQuery', () => {
6
  for (const [input, expected] of [
7
    [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'],
8
    [{ a: null, b: false, c: undefined }, 'a=&b=false'],
9
    [{ 'a/b': 1.28341 }, `${encodeURIComponent('a/b')}=1.28341`],
10
    [
11
      { 'a/b': 'c/d', 'e=f': 'g&h' },
12
      `${encodeURIComponent('a/b')}=${encodeURIComponent('c/d')}&${encodeURIComponent(
13
        'e=f',
14
      )}=${encodeURIComponent('g&h')}`,
15
    ],
16
  ]) {
17
    it(`${JSON.stringify(input)} -> ${expected}`, () => {
18
      expect(stringifyQuery(input)).toEqual(expected);
19
    });
20
  }
21
  for (const value of [[], {}, new Date()]) {
22
    it(`${JSON.stringify(value)} -> <error>`, () => {
23
      expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`);
24
    });
25
  }
26
});
27

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.