Skip to content

Commit

Permalink
chore(tests): add query string tests to ecosystem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored and stainless-bot committed Sep 17, 2024
1 parent f870682 commit 36be724
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 5 deletions.
37 changes: 32 additions & 5 deletions ecosystem-tests/node-js/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
const openaiKey = "a valid OpenAI key"
const OpenAI = require('openai');

console.log(OpenAI)
const openai = new OpenAI();

const openai = new OpenAI({
apiKey: openaiKey,
});
function assertEqual(actual, expected) {
if (actual === expected) {
return;
}

console.error('expected', expected);
console.error('actual ', actual);
throw new Error('expected values to be equal');
}

async function main() {
const completion = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Say this is a test' }],
});
if (!completion.choices[0].message.content) {
console.dir(completion, { depth: 4 });
throw new Error('no response content!');
}

assertEqual(
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
'foo[nested][a]=true&foo[nested][b]=foo',
);
assertEqual(
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
'foo[nested][a][]=hello&foo[nested][a][]=world',
);
}

main();
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-cjs-auto/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-cjs-web/tests/test-jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ describe.skip('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-cjs-web/tests/test-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-cjs/tests/test-jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ describe.skip('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-cjs/tests/test-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-esm-auto/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-esm-web/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-esm/tests/test-esnext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ it(`raw response`, async function () {
const json: ChatCompletion = JSON.parse(chunks.join(''));
expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts-esm/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/node-ts4.5-jest27/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ describe('toFile', () => {
expect(result.filename).toEqual('finetune.jsonl');
});
});

test('query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});
9 changes: 9 additions & 0 deletions ecosystem-tests/ts-browser-webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,13 @@ describe('toFile', () => {
});
});

it('handles query strings', () => {
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
expect(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
});

runTests();
11 changes: 11 additions & 0 deletions ecosystem-tests/vercel-edge/src/uploadWebApiTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,15 @@ export function uploadWebApiTestCases({
expectEqual(result.filename, 'finetune.jsonl');
});
}

it('handles query strings', async () => {
expectEqual(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
'foo[nested][a]=true&foo[nested][b]=foo',
);
expectEqual(
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
'foo[nested][a][]=hello&foo[nested][a][]=world',
);
});
}

0 comments on commit 36be724

Please sign in to comment.