summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authormihna123 <mihailonvojinovic@gmail.com>2026-08-29 23:56:50 +0200
committermihna123 <mihailonvojinovic@gmail.com>2026-08-29 23:56:50 +0200
commita57f4fcbcd7857286cff854f6d62285df7d098aa (patch)
treec41d040df8043054d1a1d08141accc3540f226e4 /internal
parentdd5b51334b49f4b000ba961986801ea9b9112aac (diff)
downloadopenstore-master.tar.gz
openstore-master.zip
user: check errors type and fail now where needed in testsHEADmaster
Diffstat (limited to 'internal')
-rw-r--r--internal/user/service_test.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/internal/user/service_test.go b/internal/user/service_test.go
index f3dcfd6..d6f5c3d 100644
--- a/internal/user/service_test.go
+++ b/internal/user/service_test.go
@@ -39,25 +39,27 @@ func TestRegisterBadInput(t *testing.T) {
in := &RegisterInput{}
s := newTestUserService(t)
_, err := s.Register(in)
+
if err == nil {
t.Error("no error when registering with faulty input")
}
+
+ if !errors.Is(err, ErrInvalidInput) {
+ t.Errorf("unexpected error: got %v, want ErrInvalidInput", err)
+ }
}
func TestRegisterExistingUser(t *testing.T) {
- r := newEmptyRepository()
- r.fill()
-
badInputs := map[string]RegisterInput{
"existing username": {
- Username: r.users[0].Username,
+ Username: "johnsmith",
Email: "thisemaildoesnt@exist.com",
Phone: "123321",
Password: "22332233",
},
"existing email": {
Username: "thisusernamedoesntexist",
- Email: r.users[0].Email,
+ Email: "janedoe@email.com",
Phone: "123321",
Password: "22332233",
},
@@ -65,7 +67,10 @@ func TestRegisterExistingUser(t *testing.T) {
for name, in := range badInputs {
t.Run(name, func(t *testing.T) {
+ r := newEmptyRepository()
+ r.fill()
s := &Service{repository: r, bcryptCost: bcrypt.MinCost}
+
_, err := s.Register(&in)
if err == nil {
t.Error("existing user registered")
@@ -124,7 +129,9 @@ func TestRegisterSameUserTwice(t *testing.T) {
Password: "supersecretpassword1234",
}
- s.Register(in)
+ if _, err := s.Register(in); err != nil {
+ t.Fatalf("first register failed: %v", err)
+ }
_, err := s.Register(in)
if err == nil {