This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: minLowercase validation strategy
- Loading branch information
1 parent
425f0bd
commit d576b82
Showing
3 changed files
with
81 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package validation | ||
|
||
import "regexp" | ||
|
||
type MinLowercaseValidationStrategy struct { | ||
RegexValidation | ||
} | ||
|
||
func NewMinLowercaseValidationStrategy() MinLowercaseValidationStrategy { | ||
const MIN_LOWERCASE_REGEXP string = "[a-z]" | ||
return MinLowercaseValidationStrategy{RegexValidation: RegexValidation{ | ||
validationExpression: *regexp.MustCompile(MIN_LOWERCASE_REGEXP), | ||
}} | ||
} |
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,49 @@ | ||
package validation_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/brandaogabriel7/studio-sol-back-end-test/src/strategies/validation" | ||
) | ||
|
||
var _ = Describe("MinLowercase", func() { | ||
minLowercaseStrategy := validation.NewMinLowercaseValidationStrategy() | ||
|
||
Context("Check that the password follows minLowercase rule", func () { | ||
DescribeTable("When password contains more lower case characters than minLowercase value", | ||
func (password string, minLowercase int) { | ||
isValid := minLowercaseStrategy.IsValid(password, minLowercase) | ||
|
||
Expect(isValid).To(BeTrue()) | ||
}, | ||
Entry("minLowercase 3", "senha123456", 3), | ||
Entry("minLowercase 10", "minhasenhaaaa12", 10), | ||
Entry("minLowercase 23", "eusouumasenhasuperforteesegura", 23), | ||
) | ||
|
||
DescribeTable("When password contains as many lower case characters as minLowercase value", | ||
func (password string, minLowercase int) { | ||
isValid := minLowercaseStrategy.IsValid(password, minLowercase) | ||
|
||
Expect(isValid).To(BeTrue()) | ||
}, | ||
Entry("minLowercase 5", "senha12345", 5), | ||
Entry("minLowercase 10", "sseenhaaaa12345", 10), | ||
Entry("minLowercase 18", "eusouumasupersenha", 18), | ||
) | ||
}) | ||
|
||
Context("Check that the password does not follow minLowercase rule", func () { | ||
DescribeTable("When password has less lower case characters than minLowercase value", | ||
func (password string, minLowercase int) { | ||
isValid := minLowercaseStrategy.IsValid(password, minLowercase) | ||
|
||
Expect(isValid).To(BeFalse()) | ||
}, | ||
Entry("minLowercase 5", "opa", 5), | ||
Entry("minLowercase 10", "superSenha321", 10), | ||
Entry("minLowercase 30", "SuperS3nh@Forte", 30), | ||
) | ||
}) | ||
}) |