|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { AgentUtils, isDynamicConnection } from '../Utils'; |
| 3 | + |
| 4 | +describe('AgentUtils', () => { |
| 5 | + describe('ModelType constants', () => { |
| 6 | + it('should have correct model type values', () => { |
| 7 | + expect(AgentUtils.ModelType.AzureOpenAI).toBe('Azure OpenAI'); |
| 8 | + expect(AgentUtils.ModelType.FoundryService).toBe('Foundry Agent Service'); |
| 9 | + expect(AgentUtils.ModelType.APIM).toBe('APIM Gen AI Gateway'); |
| 10 | + expect(AgentUtils.ModelType.V1ChatCompletionsService).toBe('V1 Chat Completions Service'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should not have trailing spaces in model type values', () => { |
| 14 | + // Regression test for trailing space fix in commit |
| 15 | + Object.values(AgentUtils.ModelType).forEach((modelType) => { |
| 16 | + expect(modelType).toBe(modelType.trim()); |
| 17 | + }); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('isConnector', () => { |
| 22 | + it('should return true for agent connector without leading slash', () => { |
| 23 | + expect(AgentUtils.isConnector('connectionProviders/agent')).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should return true for agent connector with leading slash', () => { |
| 27 | + expect(AgentUtils.isConnector('/connectionProviders/agent')).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should be case insensitive', () => { |
| 31 | + expect(AgentUtils.isConnector('CONNECTIONPROVIDERS/AGENT')).toBe(true); |
| 32 | + expect(AgentUtils.isConnector('ConnectionProviders/Agent')).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should return false for non-agent connectors', () => { |
| 36 | + expect(AgentUtils.isConnector('connectionProviders/office365')).toBe(false); |
| 37 | + expect(AgentUtils.isConnector('/providers/microsoft.web/connections')).toBe(false); |
| 38 | + expect(AgentUtils.isConnector('')).toBe(false); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should handle undefined input', () => { |
| 42 | + expect(AgentUtils.isConnector(undefined)).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should handle null input', () => { |
| 46 | + expect(AgentUtils.isConnector(null as any)).toBe(false); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('isDeploymentOrModelIdParameter', () => { |
| 51 | + it('should return true for deploymentId parameter', () => { |
| 52 | + expect(AgentUtils.isDeploymentOrModelIdParameter('deploymentId')).toBe(true); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should return true for modelId parameter', () => { |
| 56 | + expect(AgentUtils.isDeploymentOrModelIdParameter('modelId')).toBe(true); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should be case insensitive for deploymentId', () => { |
| 60 | + expect(AgentUtils.isDeploymentOrModelIdParameter('DEPLOYMENTID')).toBe(true); |
| 61 | + expect(AgentUtils.isDeploymentOrModelIdParameter('DeploymentId')).toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should be case insensitive for modelId', () => { |
| 65 | + expect(AgentUtils.isDeploymentOrModelIdParameter('MODELID')).toBe(true); |
| 66 | + expect(AgentUtils.isDeploymentOrModelIdParameter('ModelId')).toBe(true); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return false for other parameter names', () => { |
| 70 | + expect(AgentUtils.isDeploymentOrModelIdParameter('agentModelType')).toBe(false); |
| 71 | + expect(AgentUtils.isDeploymentOrModelIdParameter('messages')).toBe(false); |
| 72 | + expect(AgentUtils.isDeploymentOrModelIdParameter('deployment')).toBe(false); |
| 73 | + expect(AgentUtils.isDeploymentOrModelIdParameter('model')).toBe(false); |
| 74 | + expect(AgentUtils.isDeploymentOrModelIdParameter('')).toBe(false); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should handle undefined input', () => { |
| 78 | + expect(AgentUtils.isDeploymentOrModelIdParameter(undefined)).toBe(false); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should handle null input', () => { |
| 82 | + expect(AgentUtils.isDeploymentOrModelIdParameter(null as any)).toBe(false); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('isAgentModelTypeParameter', () => { |
| 87 | + it('should return true for agentModelType parameter', () => { |
| 88 | + expect(AgentUtils.isAgentModelTypeParameter('agentModelType')).toBe(true); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should be case insensitive', () => { |
| 92 | + expect(AgentUtils.isAgentModelTypeParameter('AGENTMODELTYPE')).toBe(true); |
| 93 | + expect(AgentUtils.isAgentModelTypeParameter('AgentModelType')).toBe(true); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should return false for other parameter names', () => { |
| 97 | + expect(AgentUtils.isAgentModelTypeParameter('deploymentId')).toBe(false); |
| 98 | + expect(AgentUtils.isAgentModelTypeParameter('modelId')).toBe(false); |
| 99 | + expect(AgentUtils.isAgentModelTypeParameter('agentModel')).toBe(false); |
| 100 | + expect(AgentUtils.isAgentModelTypeParameter('')).toBe(false); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should handle undefined input', () => { |
| 104 | + expect(AgentUtils.isAgentModelTypeParameter(undefined)).toBe(false); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should handle null input', () => { |
| 108 | + expect(AgentUtils.isAgentModelTypeParameter(null as any)).toBe(false); |
| 109 | + }); |
| 110 | + }); |
| 111 | +}); |
| 112 | + |
| 113 | +describe('isDynamicConnection', () => { |
| 114 | + it('should return true for DynamicUserInvoked feature', () => { |
| 115 | + expect(isDynamicConnection('DynamicUserInvoked')).toBe(true); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should be case insensitive', () => { |
| 119 | + expect(isDynamicConnection('DYNAMICUSERINVOKED')).toBe(true); |
| 120 | + expect(isDynamicConnection('dynamicuserinvoked')).toBe(true); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should return false for other features', () => { |
| 124 | + expect(isDynamicConnection('StaticConnection')).toBe(false); |
| 125 | + expect(isDynamicConnection('CustomConnection')).toBe(false); |
| 126 | + expect(isDynamicConnection('')).toBe(false); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should handle undefined input', () => { |
| 130 | + expect(isDynamicConnection(undefined)).toBe(false); |
| 131 | + }); |
| 132 | +}); |
0 commit comments