Skip to content

Commit 940d9ca

Browse files
committed
organize tests
1 parent 1d69ad2 commit 940d9ca

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/unit/tools-utils-test.ts renamed to tests/unit/tools.utils.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { describe, expect, it } from 'vitest';
22

33
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';
56
import type { IActorInputSchema, ISchemaProperties } from '../../src/types.js';
67

78
describe('buildNestedProperties', () => {
@@ -317,3 +318,57 @@ describe('shortenProperties', () => {
317318
expect(result).toEqual(properties);
318319
});
319320
});
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

Comments
 (0)