|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | 3 | import { ACTOR_ENUM_MAX_LENGTH, ACTOR_MAX_DESCRIPTION_LENGTH } from '../../src/const.js'; |
4 | | -import { buildNestedProperties, markInputPropertiesAsRequired, shortenProperties } from '../../src/tools/utils.js'; |
| 4 | +import { buildNestedProperties, decodeDotPropertyNames, encodeDotPropertyNames, |
| 5 | + markInputPropertiesAsRequired, shortenProperties } from '../../src/tools/utils.js'; |
5 | 6 | import type { IActorInputSchema, ISchemaProperties } from '../../src/types.js'; |
6 | 7 |
|
7 | 8 | describe('buildNestedProperties', () => { |
@@ -317,3 +318,53 @@ describe('shortenProperties', () => { |
317 | 318 | expect(result).toEqual(properties); |
318 | 319 | }); |
319 | 320 | }); |
| 321 | + |
| 322 | +describe('encodeDotPropertyNames', () => { |
| 323 | + it('should replace dots in property names with -dot-', () => { |
| 324 | + const input = { |
| 325 | + 'foo.bar': { type: 'string', title: 'Foo Bar', description: 'desc' }, |
| 326 | + baz: { type: 'number', title: 'Baz', description: 'desc2' }, |
| 327 | + 'a.b.c': { type: 'boolean', title: 'A B C', description: 'desc3' }, |
| 328 | + }; |
| 329 | + const result = encodeDotPropertyNames(input); |
| 330 | + expect(result['foo-dot-bar']).toBeDefined(); |
| 331 | + expect(result['a-dot-b-dot-c']).toBeDefined(); |
| 332 | + expect(result.baz).toBeDefined(); |
| 333 | + expect(result['foo.bar']).toBeUndefined(); |
| 334 | + expect(result['a.b.c']).toBeUndefined(); |
| 335 | + }); |
| 336 | + |
| 337 | + it('should not modify property names without dots', () => { |
| 338 | + const input = { |
| 339 | + foo: { type: 'string', title: 'Foo', description: 'desc' }, |
| 340 | + bar: { type: 'number', title: 'Bar', description: 'desc2' }, |
| 341 | + }; |
| 342 | + const result = encodeDotPropertyNames(input); |
| 343 | + expect(result).toEqual(input); |
| 344 | + }); |
| 345 | +}); |
| 346 | + |
| 347 | +describe('decodeDotPropertyNames', () => { |
| 348 | + it('should replace -dot- in property names with dots', () => { |
| 349 | + const input = { |
| 350 | + 'foo-dot-bar': { type: 'string', title: 'Foo Bar', description: 'desc' }, |
| 351 | + baz: { type: 'number', title: 'Baz', description: 'desc2' }, |
| 352 | + 'a-dot-b-dot-c': { type: 'boolean', title: 'A B C', description: 'desc3' }, |
| 353 | + }; |
| 354 | + const result = decodeDotPropertyNames(input); |
| 355 | + expect(result['foo.bar']).toBeDefined(); |
| 356 | + expect(result['a.b.c']).toBeDefined(); |
| 357 | + expect(result.baz).toBeDefined(); |
| 358 | + expect(result['foo-dot-bar']).toBeUndefined(); |
| 359 | + expect(result['a-dot-b-dot-c']).toBeUndefined(); |
| 360 | + }); |
| 361 | + |
| 362 | + it('should not modify property names without -dot-', () => { |
| 363 | + const input = { |
| 364 | + foo: { type: 'string', title: 'Foo', description: 'desc' }, |
| 365 | + bar: { type: 'number', title: 'Bar', description: 'desc2' }, |
| 366 | + }; |
| 367 | + const result = decodeDotPropertyNames(input); |
| 368 | + expect(result).toEqual(input); |
| 369 | + }); |
| 370 | +}); |
0 commit comments