From d4af46327b8d679e47c1523b3049784b4f20e9c7 Mon Sep 17 00:00:00 2001 From: Johnpaul Date: Wed, 21 Jan 2026 21:55:29 +0100 Subject: [PATCH] refactor: remove any types from algoliaSearchProvider.test.ts - Define RegistryNodePack type from comfyRegistryTypes - Create GlobalWithAlgolia interface for global properties - Replace (global as any) with properly typed (globalThis as unknown as GlobalWithAlgolia) - Type testPack and incompletePack as Partial - Replace as any casts with as RegistryNodePack --- .../providers/algoliaSearchProvider.test.ts | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/services/providers/algoliaSearchProvider.test.ts b/src/services/providers/algoliaSearchProvider.test.ts index b4afa64ebf..0846a67258 100644 --- a/src/services/providers/algoliaSearchProvider.test.ts +++ b/src/services/providers/algoliaSearchProvider.test.ts @@ -2,12 +2,21 @@ import type { Mock } from 'vitest' import { liteClient as algoliasearch } from 'algoliasearch/dist/lite/builds/browser' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { components } from '@/types/comfyRegistryTypes' import { useAlgoliaSearchProvider } from '@/services/providers/algoliaSearchProvider' import { SortableAlgoliaField } from '@/workbench/extensions/manager/types/comfyManagerTypes' +type RegistryNodePack = components['schemas']['Node'] + +interface GlobalWithAlgolia { + __ALGOLIA_APP_ID__: string + __ALGOLIA_API_KEY__: string +} + // Mock global Algolia constants -;(global as any).__ALGOLIA_APP_ID__ = 'test-app-id' -;(global as any).__ALGOLIA_API_KEY__ = 'test-api-key' +;(globalThis as unknown as GlobalWithAlgolia).__ALGOLIA_APP_ID__ = 'test-app-id' +;(globalThis as unknown as GlobalWithAlgolia).__ALGOLIA_API_KEY__ = + 'test-api-key' // Mock algoliasearch vi.mock('algoliasearch/dist/lite/builds/browser', () => ({ @@ -259,7 +268,7 @@ describe('useAlgoliaSearchProvider', () => { }) describe('getSortValue', () => { - const testPack = { + const testPack: Partial = { id: '1', name: 'Test Pack', downloads: 100, @@ -286,7 +295,10 @@ describe('useAlgoliaSearchProvider', () => { const createdTimestamp = new Date('2024-01-01T10:00:00Z').getTime() expect( - provider.getSortValue(testPack as any, SortableAlgoliaField.Created) + provider.getSortValue( + testPack as RegistryNodePack, + SortableAlgoliaField.Created + ) ).toBe(createdTimestamp) const updatedTimestamp = new Date('2024-01-15T10:00:00Z').getTime() @@ -296,23 +308,35 @@ describe('useAlgoliaSearchProvider', () => { }) it('should handle missing values', () => { - const incompletePack = { id: '1', name: 'Incomplete' } + const incompletePack: Partial = { + id: '1', + name: 'Incomplete' + } const provider = useAlgoliaSearchProvider() expect( - provider.getSortValue(incompletePack, SortableAlgoliaField.Downloads) + provider.getSortValue( + incompletePack as RegistryNodePack, + SortableAlgoliaField.Downloads + ) ).toBe(0) expect( - provider.getSortValue(incompletePack, SortableAlgoliaField.Publisher) + provider.getSortValue( + incompletePack as RegistryNodePack, + SortableAlgoliaField.Publisher + ) ).toBe('') expect( provider.getSortValue( - incompletePack as any, + incompletePack as RegistryNodePack, SortableAlgoliaField.Created ) ).toBe(0) expect( - provider.getSortValue(incompletePack, SortableAlgoliaField.Updated) + provider.getSortValue( + incompletePack as RegistryNodePack, + SortableAlgoliaField.Updated + ) ).toBe(0) }) })