Skip to content

Commit

Permalink
test(context): add more explicit test case names
Browse files Browse the repository at this point in the history
  • Loading branch information
bastean committed Jun 9, 2024
1 parent db8fc5b commit 5027a31
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 49 deletions.
1 change: 0 additions & 1 deletion pkg/context/shared/domain/valueobjs/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (email *Email) Value() string {

func (email *Email) IsValid() error {
validate := validator.New(validator.WithRequiredStructEnabled())

return validate.Struct(email)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/context/shared/domain/valueobjs/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (id *Id) Value() string {

func (id *Id) IsValid() error {
validate := validator.New(validator.WithRequiredStructEnabled())

return validate.Struct(id)
}

Expand All @@ -32,7 +31,7 @@ func NewId(id string) (models.ValueObject[string], error) {
if idVO.IsValid() != nil {
return nil, errors.NewInvalidValue(&errors.Bubble{
Where: "NewId",
What: "invalid id format",
What: "invalid uuid4 format",
Why: errors.Meta{
"Id": id,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/context/user/application/create/command.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
)

func RandomCommand() *Command {
id, _ := valueobj.RandomId()
email, _ := valueobj.RandomEmail()
username, _ := valueobj.RandomUsername()
password, _ := valueobj.RandomPassword()
id, _ := valueobj.IdWithValidValue()
email, _ := valueobj.EmailWithValidValue()
username, _ := valueobj.UsernameWithValidValue()
password, _ := valueobj.PasswordWithValidValue()

return &Command{
Id: id.Value(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/delete/command.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

func RandomCommand() *Command {
id, _ := valueobj.RandomId()
password, _ := valueobj.RandomPassword()
id, _ := valueobj.IdWithValidValue()
password, _ := valueobj.PasswordWithValidValue()

return &Command{
Id: id.Value(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/login/query.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

func RandomQuery() *Query {
email, _ := valueobj.RandomEmail()
password, _ := valueobj.RandomPassword()
email, _ := valueobj.EmailWithValidValue()
password, _ := valueobj.PasswordWithValidValue()

return &Query{
Email: email.Value(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/user/application/read/query.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func RandomQuery() *Query {
id, _ := valueobj.RandomId()
id, _ := valueobj.IdWithValidValue()

return &Query{
Id: id.Value(),
Expand Down
10 changes: 5 additions & 5 deletions pkg/context/user/application/update/command.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
)

func RandomCommand() *Command {
id, _ := valueobj.RandomId()
email, _ := valueobj.RandomEmail()
username, _ := valueobj.RandomUsername()
password, _ := valueobj.RandomPassword()
updatedPassword, _ := valueobj.RandomPassword()
id, _ := valueobj.IdWithValidValue()
email, _ := valueobj.EmailWithValidValue()
username, _ := valueobj.UsernameWithValidValue()
password, _ := valueobj.PasswordWithValidValue()
updatedPassword, _ := valueobj.PasswordWithValidValue()

return &Command{
Id: id.Value(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/user/application/verify/command.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func RandomCommand() *Command {
id, _ := valueobj.RandomId()
id, _ := valueobj.IdWithValidValue()

return &Command{
Id: id.Value(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/context/user/domain/aggregate/user.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
)

func RandomUser() *User {
id, _ := valueobj.RandomId()
email, _ := valueobj.RandomEmail()
username, _ := valueobj.RandomUsername()
password, _ := valueobj.RandomPassword()
id, _ := valueobj.IdWithValidValue()
email, _ := valueobj.EmailWithValidValue()
username, _ := valueobj.UsernameWithValidValue()
password, _ := valueobj.PasswordWithValidValue()

user, _ := NewUser(&UserPrimitive{
Id: id.Value(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/domain/valueobj/email.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"github.com/bastean/codexgo/pkg/context/shared/domain/services"
)

func RandomEmail() (models.ValueObject[string], error) {
func EmailWithValidValue() (models.ValueObject[string], error) {
return NewEmail(services.Create.Email())
}

func InvalidEmail() (string, error) {
func EmailWithInvalidValue() (string, error) {
value := "x"

_, err := NewEmail(value)
Expand Down
9 changes: 7 additions & 2 deletions pkg/context/user/domain/valueobj/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ type EmailValueObjectTestSuite struct {

func (suite *EmailValueObjectTestSuite) SetupTest() {}

func (suite *EmailValueObjectTestSuite) TestEmail() {
email, err := valueobj.InvalidEmail()
func (suite *EmailValueObjectTestSuite) TestWithValidValue() {
_, err := valueobj.EmailWithValidValue()
suite.NoError(err)
}

func (suite *EmailValueObjectTestSuite) TestWithInvalidValue() {
email, err := valueobj.EmailWithInvalidValue()

var actual *errors.InvalidValue

Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/domain/valueobj/id.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"github.com/bastean/codexgo/pkg/context/shared/domain/services"
)

func RandomId() (models.ValueObject[string], error) {
func IdWithValidValue() (models.ValueObject[string], error) {
return NewId(services.Create.UUID())
}

func InvalidId() (string, error) {
func IdWithInvalidValue() (string, error) {
value := "x"

_, err := NewId(value)
Expand Down
11 changes: 8 additions & 3 deletions pkg/context/user/domain/valueobj/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ type IdValueObjectTestSuite struct {

func (suite *IdValueObjectTestSuite) SetupTest() {}

func (suite *IdValueObjectTestSuite) TestId() {
id, err := valueobj.InvalidId()
func (suite *IdValueObjectTestSuite) TestWithValidValue() {
_, err := valueobj.IdWithValidValue()
suite.NoError(err)
}

func (suite *IdValueObjectTestSuite) TestWithInvalidValue() {
id, err := valueobj.IdWithInvalidValue()

var actual *errors.InvalidValue

Expand All @@ -24,7 +29,7 @@ func (suite *IdValueObjectTestSuite) TestId() {
expected := errors.InvalidValue{Bubble: &errors.Bubble{
When: actual.When,
Where: "NewId",
What: "invalid id format",
What: "invalid uuid4 format",
Why: errors.Meta{
"Id": id,
},
Expand Down
1 change: 0 additions & 1 deletion pkg/context/user/domain/valueobj/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (password *Password) Value() string {

func (password *Password) IsValid() error {
validate := validator.New(validator.WithRequiredStructEnabled())

return validate.Struct(password)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/domain/valueobj/password.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"github.com/bastean/codexgo/pkg/context/shared/domain/services"
)

func RandomPassword() (models.ValueObject[string], error) {
return NewPassword(services.Create.Regex(`[\W\w]{8,64}`))
func PasswordWithValidValue() (models.ValueObject[string], error) {
return NewPassword(services.Create.Regex(`^[\W\w]{8,64}$`))
}

func WithInvalidPasswordLength() (string, error) {
func PasswordWithInvalidLength() (string, error) {
value := "x"

_, err := NewPassword(value)
Expand Down
9 changes: 7 additions & 2 deletions pkg/context/user/domain/valueobj/password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ type PasswordValueObjectTestSuite struct {

func (suite *PasswordValueObjectTestSuite) SetupTest() {}

func (suite *PasswordValueObjectTestSuite) TestPassword() {
password, err := valueobj.WithInvalidPasswordLength()
func (suite *PasswordValueObjectTestSuite) TestWithValidValue() {
_, err := valueobj.PasswordWithValidValue()
suite.NoError(err)
}

func (suite *PasswordValueObjectTestSuite) TestWithInvalidLength() {
password, err := valueobj.PasswordWithInvalidLength()

var actual *errors.InvalidValue

Expand Down
1 change: 0 additions & 1 deletion pkg/context/user/domain/valueobj/username.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (username *Username) Value() string {

func (username *Username) IsValid() error {
validate := validator.New(validator.WithRequiredStructEnabled())

return validate.Struct(username)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/context/user/domain/valueobj/username.mother.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"github.com/bastean/codexgo/pkg/context/shared/domain/services"
)

func RandomUsername() (models.ValueObject[string], error) {
return NewUsername(services.Create.Regex(`[a-z0-9]{2,20}`))
func UsernameWithValidValue() (models.ValueObject[string], error) {
return NewUsername(services.Create.Regex(`^[a-z0-9]{2,20}$`))
}

func WithInvalidUsernameLength() (string, error) {
func UsernameWithInvalidLength() (string, error) {
value := "x"

_, err := NewUsername(value)

return value, err
}

func WithInvalidUsernameAlphanumeric() (string, error) {
func UsernameWithInvalidAlphanumeric() (string, error) {
value := "<></>"

_, err := NewUsername(value)
Expand Down
13 changes: 9 additions & 4 deletions pkg/context/user/domain/valueobj/username_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ type UsernameValueObjectTestSuite struct {

func (suite *UsernameValueObjectTestSuite) SetupTest() {}

func (suite *UsernameValueObjectTestSuite) TestUsernameWithInvalidLength() {
username, err := valueobj.WithInvalidUsernameLength()
func (suite *UsernameValueObjectTestSuite) TestWithValidValue() {
_, err := valueobj.UsernameWithValidValue()
suite.NoError(err)
}

func (suite *UsernameValueObjectTestSuite) TestWithInvalidLength() {
username, err := valueobj.UsernameWithInvalidLength()

var actual *errors.InvalidValue

Expand All @@ -33,8 +38,8 @@ func (suite *UsernameValueObjectTestSuite) TestUsernameWithInvalidLength() {
suite.EqualError(expected, actual.Error())
}

func (suite *UsernameValueObjectTestSuite) TestUsernameWithInvalidAlphanumeric() {
username, err := valueobj.WithInvalidUsernameAlphanumeric()
func (suite *UsernameValueObjectTestSuite) TestWithInvalidAlphanumeric() {
username, err := valueobj.UsernameWithInvalidAlphanumeric()

var actual *errors.InvalidValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (suite *UserBcryptHashingTestSuite) SetupTest() {
}

func (suite *UserBcryptHashingTestSuite) TestHash() {
password, _ := valueobj.RandomPassword()
password, _ := valueobj.PasswordWithValidValue()

plain := password.Value()

Expand All @@ -31,7 +31,7 @@ func (suite *UserBcryptHashingTestSuite) TestHash() {
}

func (suite *UserBcryptHashingTestSuite) TestIsNotEqual() {
password, _ := valueobj.RandomPassword()
password, _ := valueobj.PasswordWithValidValue()

plain := password.Value()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *UserMongoRepositoryTestSuite) TestUpdate() {

suite.NoError(suite.sut.Save(user))

password, _ := valueobj.RandomPassword()
password, _ := valueobj.PasswordWithValidValue()

user.Password = password

Expand Down

0 comments on commit 5027a31

Please sign in to comment.