@@ -113,6 +113,11 @@ func (suite *HandlerTestSuite) TestGenerateAndSendZipResponse_Success() {
113113 Size : 42 ,
114114 },
115115 },
116+ EnvFile : & EnvironmentFile {
117+ FileName : ".env" ,
118+ Content : "TEST_APP_CLIENT_ID=\n TEST_APP_CLIENT_SECRET=\n " ,
119+ Size : 44 ,
120+ },
116121 Summary : & ExportSummary {
117122 TotalFiles : 2 ,
118123 TotalSize : 84 ,
@@ -142,7 +147,7 @@ func (suite *HandlerTestSuite) TestGenerateAndSendZipResponse_Success() {
142147 // Read and verify ZIP contents
143148 zipReader , err := zip .NewReader (bytes .NewReader (zipBytes ), int64 (len (zipBytes )))
144149 assert .NoError (suite .T (), err )
145- assert .Len (suite .T (), zipReader .File , 2 )
150+ assert .Len (suite .T (), zipReader .File , 3 )
146151
147152 // Verify first file
148153 file1 := zipReader .File [0 ]
@@ -165,6 +170,17 @@ func (suite *HandlerTestSuite) TestGenerateAndSendZipResponse_Success() {
165170 assert .Equal (suite .T (), "name: test-app-2\n description: Test Application 2" , string (content2 ))
166171 err = reader2 .Close ()
167172 assert .NoError (suite .T (), err )
173+
174+ // Verify env file
175+ envFile := zipReader .File [2 ]
176+ assert .Equal (suite .T (), ".env" , envFile .Name )
177+ envReader , err := envFile .Open ()
178+ assert .NoError (suite .T (), err )
179+ envContent , err := io .ReadAll (envReader )
180+ assert .NoError (suite .T (), err )
181+ assert .Equal (suite .T (), "TEST_APP_CLIENT_ID=\n TEST_APP_CLIENT_SECRET=\n " , string (envContent ))
182+ err = envReader .Close ()
183+ assert .NoError (suite .T (), err )
168184}
169185
170186// Helper function to test ZIP response generation
@@ -425,7 +441,7 @@ func TestNewExportHandler(t *testing.T) {
425441
426442// Handler Function Tests
427443
428- // TestHandleExportRequest_Success tests successful YAML export.
444+ // TestHandleExportRequest_Success tests successful JSON export on the /export endpoint .
429445func (suite * HandlerTestSuite ) TestHandleExportRequest_Success () {
430446 // Setup mock expectations
431447 suite .mockAppService .EXPECT ().GetApplication (mock .Anything , "app1" ).Return (& model.Application {
@@ -455,12 +471,14 @@ func (suite *HandlerTestSuite) TestHandleExportRequest_Success() {
455471
456472 // Assert response
457473 assert .Equal (suite .T (), http .StatusOK , w .Code )
458- assert .Equal (suite .T (), "application/yaml " , w .Header ().Get ("Content-Type" ))
474+ assert .Equal (suite .T (), "application/json " , w .Header ().Get ("Content-Type" ))
459475
460- responseBody := w .Body .String ()
461- assert .NotEmpty (suite .T (), responseBody )
462- assert .Contains (suite .T (), responseBody , "# File:" )
463- assert .Contains (suite .T (), responseBody , "name: Test App 1" )
476+ var response JSONExportResponse
477+ err := json .Unmarshal (w .Body .Bytes (), & response )
478+ assert .NoError (suite .T (), err )
479+ assert .Contains (suite .T (), response .Resources , "# File: Test_App_1.yaml" )
480+ assert .Contains (suite .T (), response .Resources , "name: Test App 1" )
481+ assert .Equal (suite .T (), "" , response .EnvironmentVariables )
464482}
465483
466484// TestHandleExportRequest_InvalidJSON tests invalid JSON request handling.
@@ -505,8 +523,6 @@ func (suite *HandlerTestSuite) testServiceErrorResponse(
505523 switch endpoint {
506524 case "/export" :
507525 suite .handler .HandleExportRequest (w , req )
508- case "/export/json" :
509- suite .handler .HandleExportJSONRequest (w , req )
510526 case "/export/zip" :
511527 suite .handler .HandleExportZipRequest (w , req )
512528 }
@@ -526,7 +542,7 @@ func (suite *HandlerTestSuite) TestHandleExportRequest_ServiceError() {
526542 suite .testServiceErrorResponse ("POST" , "/export" , "app1" , & ErrorNoResourcesFound , "EXP-1002" )
527543}
528544
529- // TestHandleExportRequest_MultipleFiles tests YAML export with multiple files.
545+ // TestHandleExportRequest_MultipleFiles tests JSON export with multiple files.
530546func (suite * HandlerTestSuite ) TestHandleExportRequest_MultipleFiles () {
531547 // Setup mock expectations for multiple applications
532548 suite .mockAppService .EXPECT ().GetApplication (mock .Anything , "app1" ).Return (& model.Application {
@@ -554,16 +570,17 @@ func (suite *HandlerTestSuite) TestHandleExportRequest_MultipleFiles() {
554570
555571 // Assert response
556572 assert .Equal (suite .T (), http .StatusOK , w .Code )
557- responseBody := w .Body .String ()
558-
559- // Verify YAML separator between files
560- assert .Contains (suite .T (), responseBody , "---" )
561- assert .Contains (suite .T (), responseBody , "name: App One" )
562- assert .Contains (suite .T (), responseBody , "name: App Two" )
573+ assert .Equal (suite .T (), "application/json" , w .Header ().Get ("Content-Type" ))
563574
564- // Count file headers
565- fileHeaders := strings .Count (responseBody , "# File:" )
566- assert .Equal (suite .T (), 2 , fileHeaders )
575+ var response JSONExportResponse
576+ err := json .Unmarshal (w .Body .Bytes (), & response )
577+ assert .NoError (suite .T (), err )
578+ assert .Contains (suite .T (), response .Resources , "# File: App_One.yaml" )
579+ assert .Contains (suite .T (), response .Resources , "# File: App_Two.yaml" )
580+ assert .Contains (suite .T (), response .Resources , "name: App One" )
581+ assert .Contains (suite .T (), response .Resources , "name: App Two" )
582+ assert .Contains (suite .T (), response .Resources , "---" )
583+ assert .Equal (suite .T (), "" , response .EnvironmentVariables )
567584}
568585
569586// TestHandleExportJSONRequest_Success tests successful JSON export.
@@ -585,37 +602,34 @@ func (suite *HandlerTestSuite) TestHandleExportJSONRequest_Success() {
585602 requestJSON , _ := json .Marshal (requestBody )
586603
587604 // Create HTTP request
588- req := httptest .NewRequest ("POST" , "/export/json " , bytes .NewReader (requestJSON ))
605+ req := httptest .NewRequest ("POST" , "/export" , bytes .NewReader (requestJSON ))
589606 req .Header .Set ("Content-Type" , "application/json" )
590607 w := httptest .NewRecorder ()
591608
592609 // Execute
593- suite .handler .HandleExportJSONRequest (w , req )
610+ suite .handler .HandleExportRequest (w , req )
594611
595612 // Assert response
596613 assert .Equal (suite .T (), http .StatusOK , w .Code )
597614 assert .Equal (suite .T (), "application/json" , w .Header ().Get ("Content-Type" ))
598615
599- var response ExportResponse
616+ var response JSONExportResponse
600617 err := json .Unmarshal (w .Body .Bytes (), & response )
601618 assert .NoError (suite .T (), err )
602- assert .Len (suite .T (), response .Files , 1 )
603- // Note: Service currently generates YAML files even with JSON format (fallback behavior)
604- assert .Equal (suite .T (), "Test_App_JSON.yaml" , response .Files [0 ].FileName )
605- assert .Contains (suite .T (), response .Files [0 ].Content , "Test App JSON" )
606- assert .NotNil (suite .T (), response .Summary )
607- assert .Equal (suite .T (), 1 , response .Summary .TotalFiles )
619+ assert .Contains (suite .T (), response .Resources , "# File: Test_App_JSON.yaml" )
620+ assert .Contains (suite .T (), response .Resources , "name: Test App JSON" )
621+ assert .Equal (suite .T (), "" , response .EnvironmentVariables )
608622}
609623
610624// TestHandleExportJSONRequest_InvalidJSON tests invalid JSON handling for JSON export.
611625func (suite * HandlerTestSuite ) TestHandleExportJSONRequest_InvalidJSON () {
612626 // Create malformed JSON request
613- req := httptest .NewRequest ("POST" , "/export/json " , strings .NewReader ("invalid" ))
627+ req := httptest .NewRequest ("POST" , "/export" , strings .NewReader ("invalid" ))
614628 req .Header .Set ("Content-Type" , "application/json" )
615629 w := httptest .NewRecorder ()
616630
617631 // Execute
618- suite .handler .HandleExportJSONRequest (w , req )
632+ suite .handler .HandleExportRequest (w , req )
619633
620634 // Assert error response
621635 assert .Equal (suite .T (), http .StatusBadRequest , w .Code )
@@ -630,7 +644,7 @@ func (suite *HandlerTestSuite) TestHandleExportJSONRequest_InvalidJSON() {
630644// TestHandleExportJSONRequest_ServiceError tests service error handling for JSON export.
631645func (suite * HandlerTestSuite ) TestHandleExportJSONRequest_ServiceError () {
632646 // Setup mock to return service error
633- suite .testServiceErrorResponse ("POST" , "/export/json " , "app1" , & serviceerror .InternalServerError , "EXP-1002" )
647+ suite .testServiceErrorResponse ("POST" , "/export" , "app1" , & serviceerror .InternalServerError , "EXP-1002" )
634648}
635649
636650// TestHandleExportZipRequest_Success tests successful ZIP export.
@@ -790,7 +804,7 @@ func (suite *HandlerTestSuite) TestHandleExportRequest_NilOptions() {
790804
791805 // Assert successful response with default behavior
792806 assert .Equal (suite .T (), http .StatusOK , w .Code )
793- assert .Equal (suite .T (), "application/yaml " , w .Header ().Get ("Content-Type" ))
807+ assert .Equal (suite .T (), "application/json " , w .Header ().Get ("Content-Type" ))
794808}
795809
796810// TestHandleExportJSONRequest_EmptyFiles tests JSON export with no files.
@@ -802,12 +816,12 @@ func (suite *HandlerTestSuite) TestHandleExportJSONRequest_EmptyFiles() {
802816 requestJSON , _ := json .Marshal (requestBody )
803817
804818 // Create HTTP request
805- req := httptest .NewRequest ("POST" , "/export/json " , bytes .NewReader (requestJSON ))
819+ req := httptest .NewRequest ("POST" , "/export" , bytes .NewReader (requestJSON ))
806820 req .Header .Set ("Content-Type" , "application/json" )
807821 w := httptest .NewRecorder ()
808822
809823 // Execute
810- suite .handler .HandleExportJSONRequest (w , req )
824+ suite .handler .HandleExportRequest (w , req )
811825
812826 // Assert error response (empty applications list returns NoResourcesFound error)
813827 assert .Equal (suite .T (), http .StatusBadRequest , w .Code )
@@ -919,9 +933,9 @@ func BenchmarkHandleExportJSONRequest(b *testing.B) {
919933
920934 b .ResetTimer ()
921935 for i := 0 ; i < b .N ; i ++ {
922- req := httptest .NewRequest ("POST" , "/export/json " , bytes .NewReader (requestJSON ))
936+ req := httptest .NewRequest ("POST" , "/export" , bytes .NewReader (requestJSON ))
923937 req .Header .Set ("Content-Type" , "application/json" )
924938 w := httptest .NewRecorder ()
925- handler .HandleExportJSONRequest (w , req )
939+ handler .HandleExportRequest (w , req )
926940 }
927941}
0 commit comments