From 63266f07a667844eb0ba7f3263c1bb84678c9ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Andr=C3=A9s=20Chaparro=20Quintero?= <62714297+PedroChaparro@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:36:21 -0500 Subject: [PATCH] fix: Update test block without sending a new test archive (#135) * fix(blocks): Update test block without sending a new test archive --- __tests__/integration/blocks_test.go | 22 +++++++++++++++++++ __tests__/integration/blocks_utils_test.go | 18 ++++++++------- src/blocks/infrastructure/http/controllers.go | 10 +++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/__tests__/integration/blocks_test.go b/__tests__/integration/blocks_test.go index c0a9644..59d07c0 100644 --- a/__tests__/integration/blocks_test.go +++ b/__tests__/integration/blocks_test.go @@ -186,6 +186,28 @@ func TestUpdateTestBlock(t *testing.T) { block := blocks[0].(map[string]interface{}) c.Equal(newName, block["name"].(string)) c.Equal(firstLanguageUUID, block["language_uuid"].(string)) + + // Update the test block without sending a new test archive + newName = "Update test block test - block - updated - 2" + _, status = UpdateTestBlock(&UpdateTestBlockUtilsDTO{ + blockUUID: testBlockUUID, + languageUUID: firstLanguageUUID, + blockName: newName, + cookie: cookie, + testFile: nil, + }) + c.Equal(http.StatusNoContent, status) + + // Check that the test block data was updated + laboratoryResponse, status = GetLaboratoryByUUID(cookie, laboratoryUUID) + c.Equal(http.StatusOK, status) + + blocks = laboratoryResponse["test_blocks"].([]interface{}) + c.Equal(1, len(blocks)) + + block = blocks[0].(map[string]interface{}) + c.Equal(newName, block["name"].(string)) + c.Equal(firstLanguageUUID, block["language_uuid"].(string)) } func TestDeleteTestBlock(t *testing.T) { diff --git a/__tests__/integration/blocks_utils_test.go b/__tests__/integration/blocks_utils_test.go index c2ab113..1734d89 100644 --- a/__tests__/integration/blocks_utils_test.go +++ b/__tests__/integration/blocks_utils_test.go @@ -52,17 +52,19 @@ func UpdateTestBlock(dto *UpdateTestBlockUtilsDTO) (response map[string]interfac _ = writer.WriteField("language_uuid", dto.languageUUID) // Add the test file - part, err := writer.CreateFormFile("test_archive", dto.testFile.Name()) - if err != nil { - panic(err) - } - _, err = io.Copy(part, dto.testFile) - if err != nil { - panic(err) + if dto.testFile != nil { + part, err := writer.CreateFormFile("test_archive", dto.testFile.Name()) + if err != nil { + panic(err) + } + _, err = io.Copy(part, dto.testFile) + if err != nil { + panic(err) + } } // Close the multipart form - err = writer.Close() + err := writer.Close() if err != nil { panic(err) } diff --git a/src/blocks/infrastructure/http/controllers.go b/src/blocks/infrastructure/http/controllers.go index 7777dd1..74bd891 100644 --- a/src/blocks/infrastructure/http/controllers.go +++ b/src/blocks/infrastructure/http/controllers.go @@ -91,10 +91,12 @@ func (controller *BlocksController) HandleUpdateTestBlock(c *gin.Context) { // Validate the test archive (if any) multipartHeader, err := c.FormFile("test_archive") if err != nil { - c.JSON(http.StatusBadRequest, gin.H{ - "message": "Please, make sure to send the test archive", - }) - return + if err != http.ErrMissingFile { + c.JSON(http.StatusBadRequest, gin.H{ + "message": "Please, make sure to send the test archive", + }) + return + } } if multipartHeader != nil {