diff --git a/sdk/typescript/tests/utils_http_agents.test.ts b/sdk/typescript/tests/utils_http_agents.test.ts index a7cd8e126..bd73ff0a1 100644 --- a/sdk/typescript/tests/utils_http_agents.test.ts +++ b/sdk/typescript/tests/utils_http_agents.test.ts @@ -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'; @@ -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); + }); }); diff --git a/sdk/typescript/tests/utils_pattern.test.ts b/sdk/typescript/tests/utils_pattern.test.ts index 4a1b013fb..eb90c0eba 100644 --- a/sdk/typescript/tests/utils_pattern.test.ts +++ b/sdk/typescript/tests/utils_pattern.test.ts @@ -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); + }); }); diff --git a/sdk/typescript/tests/utils_schema.test.ts b/sdk/typescript/tests/utils_schema.test.ts index cbaf20e8d..395b847da 100644 --- a/sdk/typescript/tests/utils_schema.test.ts +++ b/sdk/typescript/tests/utils_schema.test.ts @@ -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 }, + }, + }); + }); });