@@ -3,8 +3,10 @@ import type {
33 ServerInfo ,
44 ServerResources ,
55 Environment ,
6- Application ,
7- CreateApplicationRequest ,
6+ CoolifyConfig ,
7+ Deployment ,
8+ Project ,
9+ ResourceStatus ,
810} from '../types/coolify.js' ;
911
1012// Mock fetch globally
@@ -300,158 +302,51 @@ describe('CoolifyClient', () => {
300302 } ) ;
301303 } ) ;
302304
303- describe ( 'Application Management' , ( ) => {
304- const mockApplication : Application = {
305- id : 1 ,
306- uuid : 'test-app-uuid' ,
307- name : 'test-app' ,
308- environment_uuid : 'test-env-uuid' ,
309- project_uuid : 'test-project-uuid' ,
310- git_repository : 'https://github.com/test/repo' ,
311- git_branch : 'main' ,
312- build_pack : 'nixpacks' ,
313- ports_exposes : '3000' ,
314- status : 'running' ,
315- created_at : '2024-03-05T12:00:00Z' ,
316- updated_at : '2024-03-05T12:00:00Z' ,
317- } ;
318-
319- describe ( 'listApplications' , ( ) => {
320- it ( 'should fetch all applications when no environment UUID is provided' , async ( ) => {
321- mockFetch . mockResolvedValueOnce ( {
322- ok : true ,
323- json : async ( ) => [ mockApplication ] ,
324- } ) ;
325-
326- const result = await client . listApplications ( ) ;
327-
328- expect ( result ) . toEqual ( [ mockApplication ] ) ;
329- expect ( mockFetch ) . toHaveBeenCalledWith (
330- 'http://test.coolify.io/api/v1/applications' ,
331- expect . objectContaining ( {
332- headers : expect . objectContaining ( {
333- Authorization : 'Bearer test-token' ,
334- } ) ,
335- } ) ,
336- ) ;
337- } ) ;
338-
339- it ( 'should fetch applications filtered by environment UUID' , async ( ) => {
340- mockFetch . mockResolvedValueOnce ( {
341- ok : true ,
342- json : async ( ) => [ mockApplication ] ,
343- } ) ;
344-
345- const result = await client . listApplications ( 'test-env-uuid' ) ;
346-
347- expect ( result ) . toEqual ( [ mockApplication ] ) ;
348- expect ( mockFetch ) . toHaveBeenCalledWith (
349- 'http://test.coolify.io/api/v1/applications?environment_uuid=test-env-uuid' ,
350- expect . objectContaining ( {
351- headers : expect . objectContaining ( {
352- Authorization : 'Bearer test-token' ,
353- } ) ,
354- } ) ,
355- ) ;
356- } ) ;
357- } ) ;
358-
359- describe ( 'getApplication' , ( ) => {
360- it ( 'should fetch application details successfully' , async ( ) => {
361- mockFetch . mockResolvedValueOnce ( {
362- ok : true ,
363- json : async ( ) => mockApplication ,
364- } ) ;
365-
366- const result = await client . getApplication ( 'test-app-uuid' ) ;
305+ describe ( 'deployApplication' , ( ) => {
306+ it ( 'should deploy an application' , async ( ) => {
307+ const mockDeployment : Deployment = {
308+ id : 1 ,
309+ uuid : 'test-deployment-uuid' ,
310+ application_uuid : 'test-app-uuid' ,
311+ status : 'running' ,
312+ created_at : '2024-03-20T12:00:00Z' ,
313+ updated_at : '2024-03-20T12:00:00Z' ,
314+ } ;
367315
368- expect ( result ) . toEqual ( mockApplication ) ;
369- expect ( mockFetch ) . toHaveBeenCalledWith (
370- 'http://test.coolify.io/api/v1/applications/test-app-uuid' ,
371- expect . objectContaining ( {
372- headers : expect . objectContaining ( {
373- Authorization : 'Bearer test-token' ,
374- } ) ,
375- } ) ,
376- ) ;
316+ mockFetch . mockResolvedValueOnce ( {
317+ ok : true ,
318+ json : ( ) => Promise . resolve ( mockDeployment ) ,
377319 } ) ;
378- } ) ;
379-
380- describe ( 'createApplication' , ( ) => {
381- it ( 'should create a new application successfully' , async ( ) => {
382- mockFetch . mockResolvedValueOnce ( {
383- ok : true ,
384- json : async ( ) => mockApplication ,
385- } ) ;
386320
387- const createRequest : CreateApplicationRequest = {
388- project_uuid : 'test-project-uuid' ,
389- environment_uuid : 'test-env-uuid' ,
390- git_repository : 'https://github.com/test/repo' ,
391- git_branch : 'main' ,
392- build_pack : 'nixpacks' ,
393- ports_exposes : '3000' ,
394- name : 'test-app' ,
395- } ;
396-
397- const result = await client . createApplication ( createRequest ) ;
398-
399- expect ( result ) . toEqual ( mockApplication ) ;
400- expect ( mockFetch ) . toHaveBeenCalledWith (
401- 'http://test.coolify.io/api/v1/applications/public' ,
402- expect . objectContaining ( {
403- method : 'POST' ,
404- body : JSON . stringify ( createRequest ) ,
405- headers : expect . objectContaining ( {
406- Authorization : 'Bearer test-token' ,
407- } ) ,
321+ const result = await client . deployApplication ( 'test-app-uuid' ) ;
322+ expect ( result ) . toEqual ( mockDeployment ) ;
323+ expect ( mockFetch ) . toHaveBeenCalledWith (
324+ 'http://test.coolify.io/api/v1/applications/test-app-uuid/deploy' ,
325+ expect . objectContaining ( {
326+ method : 'POST' ,
327+ headers : expect . objectContaining ( {
328+ Authorization : 'Bearer test-token' ,
329+ 'Content-Type' : 'application/json' ,
408330 } ) ,
409- ) ;
410- } ) ;
331+ } ) ,
332+ ) ;
411333 } ) ;
412334
413- describe ( 'deleteApplication' , ( ) => {
414- it ( 'should delete an application successfully' , async ( ) => {
415- mockFetch . mockResolvedValueOnce ( {
416- ok : true ,
417- json : async ( ) => ( { } ) ,
418- } ) ;
419-
420- await client . deleteApplication ( 'test-app-uuid' ) ;
335+ it ( 'should handle errors when deploying an application' , async ( ) => {
336+ const errorResponse = {
337+ error : 'Error' ,
338+ status : 500 ,
339+ message : 'Failed to deploy application' ,
340+ } ;
421341
422- expect ( mockFetch ) . toHaveBeenCalledWith (
423- 'http://test.coolify.io/api/v1/applications/test-app-uuid' ,
424- expect . objectContaining ( {
425- method : 'DELETE' ,
426- headers : expect . objectContaining ( {
427- Authorization : 'Bearer test-token' ,
428- } ) ,
429- } ) ,
430- ) ;
342+ mockFetch . mockResolvedValueOnce ( {
343+ ok : false ,
344+ json : ( ) => Promise . resolve ( errorResponse ) ,
431345 } ) ;
432- } ) ;
433346
434- describe ( 'deployApplication' , ( ) => {
435- it ( 'should make a POST request to deploy an application' , async ( ) => {
436- const mockDeployment = { id : 'test-deployment' } ;
437- mockFetch . mockResolvedValueOnce ( {
438- ok : true ,
439- json : async ( ) => mockDeployment ,
440- } ) ;
441-
442- const result = await client . deployApplication ( 'test-app-uuid' ) ;
443-
444- expect ( mockFetch ) . toHaveBeenCalledWith (
445- 'http://test.coolify.io/api/v1/applications/test-app-uuid/deploy' ,
446- expect . objectContaining ( {
447- method : 'POST' ,
448- headers : expect . objectContaining ( {
449- Authorization : 'Bearer test-token' ,
450- } ) ,
451- } ) ,
452- ) ;
453- expect ( result ) . toEqual ( mockDeployment ) ;
454- } ) ;
347+ await expect ( client . deployApplication ( 'test-app-uuid' ) ) . rejects . toThrow (
348+ 'Failed to deploy application'
349+ ) ;
455350 } ) ;
456351 } ) ;
457352} ) ;
0 commit comments