@@ -57,7 +57,11 @@ import {
5757 ServerDetails ,
5858 ServerType ,
5959} from "../../src/models/connectionsModels" ;
60- import { ParamFieldType , UDAParam } from "../../src/models/uda" ;
60+ import {
61+ InvalidParamFieldErrors ,
62+ ParamFieldType ,
63+ UDAParam ,
64+ } from "../../src/models/uda" ;
6165import { MetaObjectPayload } from "../../src/models/meta" ;
6266
6367interface ITestItem extends vscode . QuickPickItem {
@@ -2195,13 +2199,23 @@ describe("Utils", () => {
21952199 } ) ;
21962200
21972201 describe ( "convertTypesToString" , ( ) => {
2202+ let dataTypesStub : sinon . SinonStub ;
2203+
2204+ beforeEach ( ( ) => {
2205+ dataTypesStub = sinon . stub ( ext . constants , "dataTypes" ) ;
2206+ } ) ;
2207+
2208+ afterEach ( ( ) => {
2209+ dataTypesStub . restore ( ) ;
2210+ } ) ;
2211+
21982212 it ( "should convert types to strings" , ( ) => {
21992213 const types = [ 1 , 2 ] ;
22002214 const dataTypes = new Map ( [
22012215 [ "1" , "Boolean" ] ,
22022216 [ "2" , "Number" ] ,
22032217 ] ) ;
2204- sinon . stub ( ext . constants , "dataTypes" ) . value ( dataTypes ) ;
2218+ dataTypesStub . value ( dataTypes ) ;
22052219
22062220 const result = UDAUtils . convertTypesToString ( types ) ;
22072221 assert . deepStrictEqual ( result , [ "Boolean" , "Number" ] ) ;
@@ -2210,11 +2224,149 @@ describe("Utils", () => {
22102224 it ( "should convert type to string" , ( ) => {
22112225 const types = [ 1 ] ;
22122226 const dataTypes = new Map ( [ [ "1" , "Boolean" ] ] ) ;
2213- sinon . stub ( ext . constants , "dataTypes" ) . value ( dataTypes ) ;
2227+ dataTypesStub . value ( dataTypes ) ;
22142228
22152229 const result = UDAUtils . convertTypesToString ( types ) ;
22162230 assert . deepStrictEqual ( result , [ "Boolean" ] ) ;
22172231 } ) ;
2232+
2233+ it ( "should handle empty array" , ( ) => {
2234+ const types : number [ ] = [ ] ;
2235+ const dataTypes = new Map ( ) ;
2236+ dataTypesStub . value ( dataTypes ) ;
2237+
2238+ const result = UDAUtils . convertTypesToString ( types ) ;
2239+ assert . deepStrictEqual ( result , [ ] ) ;
2240+ } ) ;
2241+
2242+ it ( "should return type as string if not found in dataTypes map" , ( ) => {
2243+ const types = [ 3 ] ;
2244+ const dataTypes = new Map ( [
2245+ [ "1" , "Boolean" ] ,
2246+ [ "2" , "Number" ] ,
2247+ ] ) ;
2248+ dataTypesStub . value ( dataTypes ) ;
2249+
2250+ const result = UDAUtils . convertTypesToString ( types ) ;
2251+ assert . deepStrictEqual ( result , [ "3" ] ) ;
2252+ } ) ;
2253+
2254+ it ( "should handle mixed valid and invalid types" , ( ) => {
2255+ const types = [ 1 , 3 ] ;
2256+ const dataTypes = new Map ( [ [ "1" , "Boolean" ] ] ) ;
2257+ dataTypesStub . value ( dataTypes ) ;
2258+
2259+ const result = UDAUtils . convertTypesToString ( types ) ;
2260+ assert . deepStrictEqual ( result , [ "Boolean" , "3" ] ) ;
2261+ } ) ;
2262+ } ) ;
2263+
2264+ describe ( "getIncompatibleError" , ( ) => {
2265+ it ( "should return no meta error message" , ( ) => {
2266+ const result = UDAUtils . getIncompatibleError ( undefined , undefined ) ;
2267+
2268+ assert . deepEqual ( result , InvalidParamFieldErrors . NoMetadata ) ;
2269+ } ) ;
2270+
2271+ it ( "should return BadField error message" , ( ) => {
2272+ const result = UDAUtils . getIncompatibleError (
2273+ { } ,
2274+ ParamFieldType . Invalid ,
2275+ ) ;
2276+ } ) ;
2277+
2278+ it ( "should return undefined" , ( ) => {
2279+ const result = UDAUtils . getIncompatibleError (
2280+ { } ,
2281+ ParamFieldType . Boolean ,
2282+ ) ;
2283+ assert . strictEqual ( result , undefined ) ;
2284+ } ) ;
2285+ } ) ;
2286+
2287+ describe ( "UDAUtils.createUDAReturn" , ( ) => {
2288+ let convertTypesToStringStub : sinon . SinonStub ;
2289+
2290+ beforeEach ( ( ) => {
2291+ convertTypesToStringStub = sinon . stub ( UDAUtils , "convertTypesToString" ) ;
2292+ } ) ;
2293+
2294+ afterEach ( ( ) => {
2295+ convertTypesToStringStub . restore ( ) ;
2296+ } ) ;
2297+
2298+ it ( "should return correct UDAReturn when metadata has return type and description" , ( ) => {
2299+ const metadata = {
2300+ return : {
2301+ type : [ 1 , 2 ] ,
2302+ description : "Test description" ,
2303+ } ,
2304+ } ;
2305+ convertTypesToStringStub . withArgs ( [ 1 , 2 ] ) . returns ( [ "type1" , "type2" ] ) ;
2306+
2307+ const result = UDAUtils . createUDAReturn ( metadata ) ;
2308+
2309+ assert . deepStrictEqual ( result , {
2310+ type : [ "Boolean" , "Number" ] ,
2311+ description : "Test description" ,
2312+ } ) ;
2313+ } ) ;
2314+
2315+ it ( "should return empty type array and empty description when metadata is undefined" , ( ) => {
2316+ const metadata = undefined ;
2317+ convertTypesToStringStub . withArgs ( [ ] ) . returns ( [ ] ) ;
2318+
2319+ const result = UDAUtils . createUDAReturn ( metadata ) ;
2320+
2321+ assert . deepStrictEqual ( result , {
2322+ type : [ ] ,
2323+ description : "" ,
2324+ } ) ;
2325+ } ) ;
2326+
2327+ it ( "should return empty type array and empty description when metadata has no return" , ( ) => {
2328+ const metadata = undefined ;
2329+ convertTypesToStringStub . withArgs ( [ ] ) . returns ( [ ] ) ;
2330+
2331+ const result = UDAUtils . createUDAReturn ( metadata ) ;
2332+
2333+ assert . deepStrictEqual ( result , {
2334+ type : [ ] ,
2335+ description : "" ,
2336+ } ) ;
2337+ } ) ;
2338+
2339+ it ( "should return empty type array and provided description when metadata has no return type" , ( ) => {
2340+ const metadata = {
2341+ return : {
2342+ description : "Test description" ,
2343+ } ,
2344+ } ;
2345+ convertTypesToStringStub . withArgs ( [ ] ) . returns ( [ ] ) ;
2346+
2347+ const result = UDAUtils . createUDAReturn ( metadata ) ;
2348+
2349+ assert . deepStrictEqual ( result , {
2350+ type : [ ] ,
2351+ description : "Test description" ,
2352+ } ) ;
2353+ } ) ;
2354+
2355+ it ( "should return correct type array and empty description when metadata has return type but no description" , ( ) => {
2356+ const metadata = {
2357+ return : {
2358+ type : [ 1 , 2 ] ,
2359+ } ,
2360+ } ;
2361+ convertTypesToStringStub . withArgs ( [ 1 , 2 ] ) . returns ( [ "type1" , "type2" ] ) ;
2362+
2363+ const result = UDAUtils . createUDAReturn ( metadata ) ;
2364+
2365+ assert . deepStrictEqual ( result , {
2366+ type : [ "Boolean" , "Number" ] ,
2367+ description : "" ,
2368+ } ) ;
2369+ } ) ;
22182370 } ) ;
22192371
22202372 describe ( "parseUDAList" , ( ) => {
0 commit comments