Skip to content

Commit b5dbd62

Browse files
RobertCraigiestainless-app[bot]
authored andcommitted
chore(tests): add query string tests to ecosystem tests
1 parent 1eb4e12 commit b5dbd62

File tree

13 files changed

+142
-5
lines changed

13 files changed

+142
-5
lines changed

ecosystem-tests/node-js/test.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1-
const openaiKey = "a valid OpenAI key"
21
const OpenAI = require('openai');
32

4-
console.log(OpenAI)
3+
const openai = new OpenAI();
54

6-
const openai = new OpenAI({
7-
apiKey: openaiKey,
8-
});
5+
function assertEqual(actual, expected) {
6+
if (actual === expected) {
7+
return;
8+
}
9+
10+
console.error('expected', expected);
11+
console.error('actual ', actual);
12+
throw new Error('expected values to be equal');
13+
}
14+
15+
async function main() {
16+
const completion = await openai.chat.completions.create({
17+
model: 'gpt-4',
18+
messages: [{ role: 'user', content: 'Say this is a test' }],
19+
});
20+
if (!completion.choices[0].message.content) {
21+
console.dir(completion, { depth: 4 });
22+
throw new Error('no response content!');
23+
}
24+
25+
assertEqual(
26+
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
27+
'foo[nested][a]=true&foo[nested][b]=foo',
28+
);
29+
assertEqual(
30+
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
31+
'foo[nested][a][]=hello&foo[nested][a][]=world',
32+
);
33+
}
34+
35+
main();

ecosystem-tests/node-ts-cjs-auto/tests/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,12 @@ describe('toFile', () => {
257257
expect(result.filename).toEqual('finetune.jsonl');
258258
});
259259
});
260+
261+
test('query strings', () => {
262+
expect(
263+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
264+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
265+
expect(
266+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
267+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
268+
});

ecosystem-tests/node-ts-cjs-web/tests/test-jsdom.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,12 @@ describe.skip('toFile', () => {
164164
expect(result.filename).toEqual('finetune.jsonl');
165165
});
166166
});
167+
168+
test('query strings', () => {
169+
expect(
170+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
171+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
172+
expect(
173+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
174+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
175+
});

ecosystem-tests/node-ts-cjs-web/tests/test-node.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,12 @@ describe('toFile', () => {
151151
expect(result.filename).toEqual('finetune.jsonl');
152152
});
153153
});
154+
155+
test('query strings', () => {
156+
expect(
157+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
158+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
159+
expect(
160+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
161+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
162+
});

ecosystem-tests/node-ts-cjs/tests/test-jsdom.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ describe.skip('toFile', () => {
144144
expect(result.filename).toEqual('finetune.jsonl');
145145
});
146146
});
147+
148+
test('query strings', () => {
149+
expect(
150+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
151+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
152+
expect(
153+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
154+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
155+
});

ecosystem-tests/node-ts-cjs/tests/test-node.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ describe('toFile', () => {
192192
expect(result.filename).toEqual('finetune.jsonl');
193193
});
194194
});
195+
196+
test('query strings', () => {
197+
expect(
198+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
199+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
200+
expect(
201+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
202+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
203+
});

ecosystem-tests/node-ts-esm-auto/tests/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ describe('toFile', () => {
194194
expect(result.filename).toEqual('finetune.jsonl');
195195
});
196196
});
197+
198+
test('query strings', () => {
199+
expect(
200+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
201+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
202+
expect(
203+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
204+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
205+
});

ecosystem-tests/node-ts-esm-web/tests/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ describe('toFile', () => {
152152
expect(result.filename).toEqual('finetune.jsonl');
153153
});
154154
});
155+
156+
test('query strings', () => {
157+
expect(
158+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
159+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
160+
expect(
161+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
162+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
163+
});

ecosystem-tests/node-ts-esm/tests/test-esnext.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ it(`raw response`, async function () {
6464
const json: ChatCompletion = JSON.parse(chunks.join(''));
6565
expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);
6666
});
67+
68+
test('query strings', () => {
69+
expect(
70+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
71+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
72+
expect(
73+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
74+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
75+
});

ecosystem-tests/node-ts-esm/tests/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,12 @@ describe('toFile', () => {
173173
expect(result.filename).toEqual('finetune.jsonl');
174174
});
175175
});
176+
177+
test('query strings', () => {
178+
expect(
179+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
180+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
181+
expect(
182+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
183+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
184+
});

ecosystem-tests/node-ts4.5-jest27/tests/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ describe('toFile', () => {
192192
expect(result.filename).toEqual('finetune.jsonl');
193193
});
194194
});
195+
196+
test('query strings', () => {
197+
expect(
198+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
199+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
200+
expect(
201+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
202+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
203+
});

ecosystem-tests/ts-browser-webpack/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,13 @@ describe('toFile', () => {
209209
});
210210
});
211211

212+
it('handles query strings', () => {
213+
expect(
214+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
215+
).toEqual('foo[nested][a]=true&foo[nested][b]=foo');
216+
expect(
217+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
218+
).toEqual('foo[nested][a][]=hello&foo[nested][a][]=world');
219+
});
220+
212221
runTests();

ecosystem-tests/vercel-edge/src/uploadWebApiTestCases.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,15 @@ export function uploadWebApiTestCases({
180180
expectEqual(result.filename, 'finetune.jsonl');
181181
});
182182
}
183+
184+
it('handles query strings', async () => {
185+
expectEqual(
186+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
187+
'foo[nested][a]=true&foo[nested][b]=foo',
188+
);
189+
expectEqual(
190+
decodeURIComponent((client as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
191+
'foo[nested][a][]=hello&foo[nested][a][]=world',
192+
);
193+
});
183194
}

0 commit comments

Comments
 (0)