Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sdk/typescript/tests/utils_http_agents.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import http from 'node:http';
import https from 'node:https';
import { describe, it, expect } from 'vitest';

import { httpAgent, httpsAgent } from '../src/utils/httpAgents.js';
Expand All @@ -16,4 +18,12 @@ describe('http agents', () => {
expect(httpsAgent.maxTotalSockets).toBe(50);
expect(httpsAgent.maxFreeSockets).toBe(5);
});

it('httpAgent is an instance of http.Agent', () => {
expect(httpAgent).toBeInstanceOf(http.Agent);
});

it('httpsAgent is an instance of https.Agent', () => {
expect(httpsAgent).toBeInstanceOf(https.Agent);
});
});
28 changes: 28 additions & 0 deletions sdk/typescript/tests/utils_pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,32 @@ describe('matchesPattern', () => {
expect(matchesPattern('a.b+c', 'a.b+c')).toBe(true);
expect(matchesPattern('a.b+c', 'axb+c')).toBe(false);
});

it('handles empty pattern', () => {
expect(matchesPattern('', '')).toBe(true);
expect(matchesPattern('', 'a')).toBe(false);
});

it('handles empty value', () => {
expect(matchesPattern('*', '')).toBe(true);
expect(matchesPattern('test', '')).toBe(false);
});

it('handles multiple wildcards', () => {
expect(matchesPattern('a*b*c', 'axbyc')).toBe(true);
expect(matchesPattern('a*b*c', 'abc')).toBe(true);
expect(matchesPattern('a*b*c', 'axbyz')).toBe(false);
});

it('handles dots and plus signs in patterns', () => {
expect(matchesPattern('file.txt', 'file.txt')).toBe(true);
expect(matchesPattern('file.txt', 'fileXtxt')).toBe(false);
expect(matchesPattern('v1.0.0', 'v1.0.0')).toBe(true);
});

it('handles wildcard prefix with suffix', () => {
expect(matchesPattern('*.example.com', 'api.example.com')).toBe(true);
expect(matchesPattern('*.example.com', 'example.com')).toBe(false);
expect(matchesPattern('*.example.com', 'api.test.example.com')).toBe(true);
});
});
56 changes: 56 additions & 0 deletions sdk/typescript/tests/utils_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,60 @@ describe('toJsonSchema', () => {
it('returns an empty object for undefined input', () => {
expect(toJsonSchema(undefined)).toEqual({});
});

it('converts zod objects with nested fields', () => {
const schema = z.object({
name: z.string(),
age: z.number().optional(),
tags: z.array(z.string()),
});
const result = toJsonSchema(schema);
expect(result).toMatchObject({
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' },
tags: {
type: 'array',
items: { type: 'string' },
},
},
});
expect(result).not.toHaveProperty('$schema');
});

it('converts zod enums', () => {
const schema = z.enum(['a', 'b', 'c']);
const result = toJsonSchema(schema);
expect(result).toMatchObject({
type: 'string',
enum: ['a', 'b', 'c'],
});
});

it('handles non-object non-zod values', () => {
expect(toJsonSchema(42)).toEqual({});
expect(toJsonSchema('string')).toEqual({});
expect(toJsonSchema(true)).toEqual({});
});

it('preserves $schema on plain objects', () => {
const schema = { type: 'string', $schema: 'http://json-schema.org/draft-07/schema#' };
expect(toJsonSchema(schema)).toEqual(schema);
});

it('converts zod objects with default values', () => {
const schema = z.object({
name: z.string().default('hello'),
count: z.number().default(0),
});
const result = toJsonSchema(schema);
expect(result).toMatchObject({
type: 'object',
properties: {
name: { type: 'string', default: 'hello' },
count: { type: 'number', default: 0 },
},
});
});
});
Loading