@@ -267,4 +267,107 @@ describe("ApiClient", () => {
267267 await expect ( apiClient . sendEvents ( { events : mockEvents } ) ) . rejects . toThrow ( ) ;
268268 } ) ;
269269 } ) ;
270+
271+ describe ( "upgradeSharedTierCluster" , ( ) => {
272+ const upgradeOptions = {
273+ groupId : "test-group-id" ,
274+ body : {
275+ name : "MyCluster" ,
276+ providerSettings : {
277+ providerName : "FLEX" ,
278+ instanceSizeName : "FLEX" as const ,
279+ backingProviderName : "AWS" ,
280+ regionName : "US_EAST_1" ,
281+ } ,
282+ } ,
283+ } ;
284+
285+ it ( "should POST to the tenant upgrade endpoint with legacy API version headers" , async ( ) => {
286+ const mockCustomFetch = vi
287+ . spyOn ( apiClient as unknown as { customFetch : typeof fetch } , "customFetch" )
288+ . mockResolvedValue ( new Response ( JSON . stringify ( { id : "upgraded-cluster-id" } ) , { status : 200 } ) ) ;
289+
290+ const result = await apiClient . upgradeSharedTierCluster ( upgradeOptions ) ;
291+
292+ expect ( mockCustomFetch ) . toHaveBeenCalledWith (
293+ "https://api.test.com/api/atlas/v2/groups/test-group-id/clusters/tenantUpgrade" ,
294+ expect . objectContaining ( {
295+ method : "POST" ,
296+ headers : {
297+ "Content-Type" : "application/vnd.atlas.2023-01-01+json" ,
298+ Accept : "application/vnd.atlas.2023-01-01+json" ,
299+ Authorization : "Bearer mockToken" ,
300+ "User-Agent" : "test-user-agent" ,
301+ } ,
302+ body : JSON . stringify ( upgradeOptions . body ) ,
303+ } )
304+ ) ;
305+ expect ( result ) . toEqual ( { id : "upgraded-cluster-id" } ) ;
306+ } ) ;
307+
308+ it ( "should throw when the response is not ok" , async ( ) => {
309+ vi . spyOn ( apiClient as unknown as { customFetch : typeof fetch } , "customFetch" ) . mockResolvedValue (
310+ new Response ( JSON . stringify ( { error : "Bad Request" } ) , { status : 400 } )
311+ ) ;
312+
313+ await expect ( apiClient . upgradeSharedTierCluster ( upgradeOptions ) ) . rejects . toThrow ( ) ;
314+ } ) ;
315+ } ) ;
316+
317+ describe ( "upgradeFlexToDedicated" , ( ) => {
318+ const upgradeOptions = {
319+ groupId : "test-group-id" ,
320+ body : {
321+ name : "MyCluster" ,
322+ clusterType : "REPLICASET" as const ,
323+ replicationSpecs : [
324+ {
325+ regionConfigs : [
326+ {
327+ providerName : "AWS" ,
328+ regionName : "US_EAST_1" ,
329+ priority : 7 ,
330+ electableSpecs : { instanceSize : "M10" , nodeCount : 3 } ,
331+ } ,
332+ ] ,
333+ } ,
334+ ] ,
335+ autoScaling : {
336+ compute : { enabled : true , scaleDownEnabled : true , minInstanceSize : "M10" , maxInstanceSize : "M30" } ,
337+ diskGBEnabled : true ,
338+ } ,
339+ } ,
340+ } ;
341+
342+ it ( "should POST to the flex tenant upgrade endpoint with current API version headers" , async ( ) => {
343+ const mockCustomFetch = vi
344+ . spyOn ( apiClient as unknown as { customFetch : typeof fetch } , "customFetch" )
345+ . mockResolvedValue ( new Response ( JSON . stringify ( { id : "upgraded-cluster-id" } ) , { status : 200 } ) ) ;
346+
347+ const result = await apiClient . upgradeFlexToDedicated ( upgradeOptions ) ;
348+
349+ expect ( mockCustomFetch ) . toHaveBeenCalledWith (
350+ "https://api.test.com/api/atlas/v2/groups/test-group-id/flexClusters:tenantUpgrade" ,
351+ expect . objectContaining ( {
352+ method : "POST" ,
353+ headers : {
354+ "Content-Type" : "application/vnd.atlas.2025-03-12+json" ,
355+ Accept : "application/vnd.atlas.2025-03-12+json" ,
356+ Authorization : "Bearer mockToken" ,
357+ "User-Agent" : "test-user-agent" ,
358+ } ,
359+ body : JSON . stringify ( upgradeOptions . body ) ,
360+ } )
361+ ) ;
362+ expect ( result ) . toEqual ( { id : "upgraded-cluster-id" } ) ;
363+ } ) ;
364+
365+ it ( "should throw when the response is not ok" , async ( ) => {
366+ vi . spyOn ( apiClient as unknown as { customFetch : typeof fetch } , "customFetch" ) . mockResolvedValue (
367+ new Response ( JSON . stringify ( { error : "Bad Request" } ) , { status : 400 } )
368+ ) ;
369+
370+ await expect ( apiClient . upgradeFlexToDedicated ( upgradeOptions ) ) . rejects . toThrow ( ) ;
371+ } ) ;
372+ } ) ;
270373} ) ;
0 commit comments