Skip to content

Commit

Permalink
fix: Update test block without sending a new test archive (#135)
Browse files Browse the repository at this point in the history
* fix(blocks): Update test block without sending a new test archive
  • Loading branch information
PedroChaparro authored Jan 2, 2024
1 parent 4ee2c0b commit 63266f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
22 changes: 22 additions & 0 deletions __tests__/integration/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 10 additions & 8 deletions __tests__/integration/blocks_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 6 additions & 4 deletions src/blocks/infrastructure/http/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 63266f0

Please sign in to comment.