Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Updated Checks Service to hadle non selected checks scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Dec 9, 2021
1 parent bef477a commit 5b50b6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion web/services/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services

import (
"encoding/json"
"errors"
"fmt"

"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -260,9 +261,15 @@ Selected checks services
*/

func (c *checksService) GetSelectedChecksById(id string) (models.SelectedChecks, error) {
var selectedChecks models.SelectedChecks
selectedChecks := models.SelectedChecks{
ID: "",
SelectedChecks: []string{},
}

result := c.db.Where("id", id).First(&selectedChecks)
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return selectedChecks, nil
}

return selectedChecks, result.Error
}
Expand Down
5 changes: 3 additions & 2 deletions web/services/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,10 @@ func (suite *ChecksServiceTestSuite) TestChecksService_GetSelectedChecksById() {
}

func (suite *ChecksServiceTestSuite) TestChecksService_GetSelectedChecksByIdError() {
_, err := suite.checksService.GetSelectedChecksById("other")
selectedChecks, err := suite.checksService.GetSelectedChecksById("other")

suite.EqualError(err, "record not found")
suite.NoError(err)
suite.EqualValues([]string{}, selectedChecks.SelectedChecks)
}

func (suite *ChecksServiceTestSuite) TestChecksService_CreateSelectedChecks() {
Expand Down

0 comments on commit 5b50b6b

Please sign in to comment.