|
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 { actorNameToToolName, buildNestedProperties, inferArrayItemType, |
| 5 | + markInputPropertiesAsRequired, shortenEnum, 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,57 @@ describe('shortenProperties', () => { |
317 | 318 | expect(result).toEqual(properties); |
318 | 319 | }); |
319 | 320 | }); |
| 321 | + |
| 322 | +describe('actors', () => { |
| 323 | + describe('actorNameToToolName', () => { |
| 324 | + it('should replace slashes and dots with dash notation', () => { |
| 325 | + expect(actorNameToToolName('apify/web-scraper')).toBe('apify-slash-web-scraper'); |
| 326 | + expect(actorNameToToolName('my.actor.name')).toBe('my-dot-actor-dot-name'); |
| 327 | + }); |
| 328 | + |
| 329 | + it('should handle empty strings', () => { |
| 330 | + expect(actorNameToToolName('')).toBe(''); |
| 331 | + }); |
| 332 | + |
| 333 | + it('should handle strings without slashes or dots', () => { |
| 334 | + expect(actorNameToToolName('actorname')).toBe('actorname'); |
| 335 | + }); |
| 336 | + |
| 337 | + it('should handle strings with multiple slashes and dots', () => { |
| 338 | + expect(actorNameToToolName('actor/name.with/multiple.parts')).toBe('actor-slash-name-dot-with-slash-multiple-dot-parts'); |
| 339 | + }); |
| 340 | + |
| 341 | + it('should handle tool names longer than 64 characters', () => { |
| 342 | + const longName = 'a'.repeat(70); |
| 343 | + const expected = 'a'.repeat(64); |
| 344 | + expect(actorNameToToolName(longName)).toBe(expected); |
| 345 | + }); |
| 346 | + |
| 347 | + it('infers array item type from editor', () => { |
| 348 | + const property = { |
| 349 | + type: 'array', |
| 350 | + editor: 'stringList', |
| 351 | + title: '', |
| 352 | + description: '', |
| 353 | + enum: [], |
| 354 | + default: '', |
| 355 | + prefill: '', |
| 356 | + }; |
| 357 | + expect(inferArrayItemType(property)).toBe('string'); |
| 358 | + }); |
| 359 | + |
| 360 | + it('shorten enum list', () => { |
| 361 | + const enumList: string[] = []; |
| 362 | + const wordLength = 10; |
| 363 | + const wordCount = 30; |
| 364 | + |
| 365 | + for (let i = 0; i < wordCount; i++) { |
| 366 | + enumList.push('a'.repeat(wordLength)); |
| 367 | + } |
| 368 | + |
| 369 | + const shortenedList = shortenEnum(enumList); |
| 370 | + |
| 371 | + expect(shortenedList?.length || 0).toBe(ACTOR_ENUM_MAX_LENGTH / wordLength); |
| 372 | + }); |
| 373 | + }); |
| 374 | +}); |
0 commit comments