stringifyQuery.test.ts 970 B

1234567891011121314151617181920212223242526272829
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. import { Opencode } from '@opencode-ai/sdk';
  3. const { stringifyQuery } = Opencode.prototype as any;
  4. describe(stringifyQuery, () => {
  5. for (const [input, expected] of [
  6. [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'],
  7. [{ a: null, b: false, c: undefined }, 'a=&b=false'],
  8. [{ 'a/b': 1.28341 }, `${encodeURIComponent('a/b')}=1.28341`],
  9. [
  10. { 'a/b': 'c/d', 'e=f': 'g&h' },
  11. `${encodeURIComponent('a/b')}=${encodeURIComponent('c/d')}&${encodeURIComponent(
  12. 'e=f',
  13. )}=${encodeURIComponent('g&h')}`,
  14. ],
  15. ]) {
  16. it(`${JSON.stringify(input)} -> ${expected}`, () => {
  17. expect(stringifyQuery(input)).toEqual(expected);
  18. });
  19. }
  20. for (const value of [[], {}, new Date()]) {
  21. it(`${JSON.stringify(value)} -> <error>`, () => {
  22. expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`);
  23. });
  24. }
  25. });