-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forbid create/update teams with same names
- Loading branch information
1 parent
a16c390
commit d7641a5
Showing
14 changed files
with
420 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dto | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/moira-alert/moira/api" | ||
"github.com/moira-alert/moira/api/middleware" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestTeamValidation(t *testing.T) { | ||
Convey("Test team validation", t, func() { | ||
teamModel := TeamModel{} | ||
|
||
limits := api.GetTestLimitsConfig() | ||
|
||
request, _ := http.NewRequest("POST", "/api/teams", nil) | ||
request.Header.Set("Content-Type", "application/json") | ||
request = request.WithContext(middleware.SetContextValueForTest(request.Context(), "limits", limits)) | ||
|
||
Convey("with empty team.Name", func() { | ||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, errEmptyTeamName) | ||
}) | ||
|
||
Convey("with team.Name has characters more than in limit", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize+1) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, fmt.Errorf("team name cannot be longer than %d characters", limits.Team.MaxNameSize)) | ||
}) | ||
|
||
Convey("with team.Description has characters more than in limit", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize) | ||
teamModel.Description = strings.Repeat("ё", limits.Team.MaxDescriptionSize+1) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, fmt.Errorf("team description cannot be longer than %d characters", limits.Team.MaxDescriptionSize)) | ||
}) | ||
|
||
Convey("with valid team", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize) | ||
teamModel.Description = strings.Repeat("ё", limits.Team.MaxDescriptionSize) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldBeNil) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.