Explorar o código

Merge pull request #2766 from porter-dev/nafees/fix-user-tests

[POR-967] Fix failing user table-related tests
Mohammed Nafees %!s(int64=3) %!d(string=hai) anos
pai
achega
7a93a37f81

+ 36 - 16
api/server/handlers/user/create_test.go

@@ -1,7 +1,6 @@
 package user_test
 
 import (
-	"fmt"
 	"net/http"
 	"testing"
 
@@ -18,8 +17,11 @@ func TestCreateUserSuccessful(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email:    "test@test.it",
-			Password: "somepassword",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "mrp@porter.run",
+			Password:    "somepassword",
 		},
 	)
 
@@ -35,7 +37,10 @@ func TestCreateUserSuccessful(t *testing.T) {
 
 	expUser := &types.CreateUserResponse{
 		ID:            1,
-		Email:         "test@test.it",
+		FirstName:     "Mister",
+		LastName:      "Porter",
+		CompanyName:   "Porter Technologies, Inc.",
+		Email:         "mrp@porter.run",
 		EmailVerified: false,
 	}
 
@@ -50,8 +55,11 @@ func TestCreateUserBadEmail(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email:    "notanemail",
-			Password: "somepassword",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "notanemail",
+			Password:    "somepassword",
 		},
 	)
 
@@ -66,7 +74,7 @@ func TestCreateUserBadEmail(t *testing.T) {
 	handler.ServeHTTP(rr, req)
 
 	apitest.AssertResponseError(t, rr, http.StatusBadRequest, &types.ExternalError{
-		Error: fmt.Sprintf("validation failed on field 'Email' on condition 'email'"),
+		Error: "validation failed on field 'Email' on condition 'email'",
 	})
 }
 
@@ -76,7 +84,10 @@ func TestCreateUserMissingField(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email: "test@test.it",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "mrp@porter.run",
 		},
 	)
 
@@ -91,7 +102,7 @@ func TestCreateUserMissingField(t *testing.T) {
 	handler.ServeHTTP(rr, req)
 
 	apitest.AssertResponseError(t, rr, http.StatusBadRequest, &types.ExternalError{
-		Error: fmt.Sprintf("validation failed on field 'Password' on condition 'required'"),
+		Error: "validation failed on field 'Password' on condition 'required'",
 	})
 }
 
@@ -101,8 +112,11 @@ func TestCreateUserSameEmail(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email:    "test@test.it",
-			Password: "somepassword",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "mrp@porter.run",
+			Password:    "somepassword",
 		},
 	)
 
@@ -120,7 +134,7 @@ func TestCreateUserSameEmail(t *testing.T) {
 	handler.ServeHTTP(rr, req)
 
 	apitest.AssertResponseError(t, rr, http.StatusBadRequest, &types.ExternalError{
-		Error: fmt.Sprintf("email already taken"),
+		Error: "email already taken",
 	})
 }
 
@@ -130,8 +144,11 @@ func TestFailingCreateUserMethod(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email:    "test@test.it",
-			Password: "somepassword",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "mrp@porter.run",
+			Password:    "somepassword",
 		},
 	)
 
@@ -154,8 +171,11 @@ func TestFailingCreateSessionMethod(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/users",
 		&types.CreateUserRequest{
-			Email:    "test@test.it",
-			Password: "somepassword",
+			FirstName:   "Mister",
+			LastName:    "Porter",
+			CompanyName: "Porter Technologies, Inc.",
+			Email:       "mrp@porter.run",
+			Password:    "somepassword",
 		},
 	)
 

+ 4 - 1
api/server/handlers/user/current_test.go

@@ -25,7 +25,10 @@ func TestGetCurrentUserSuccessful(t *testing.T) {
 
 	expUser := &types.GetAuthenticatedUserResponse{
 		ID:            1,
-		Email:         "test@test.it",
+		FirstName:     "Mister",
+		LastName:      "Porter",
+		CompanyName:   "Porter Technologies, Inc.",
+		Email:         "mrp@porter.run",
 		EmailVerified: true,
 	}
 

+ 4 - 1
api/server/handlers/user/delete_test.go

@@ -33,7 +33,10 @@ func TestDeleteUserSuccessful(t *testing.T) {
 
 	expUser := &types.CreateUserResponse{
 		ID:            1,
-		Email:         "test@test.it",
+		FirstName:     "Mister",
+		LastName:      "Porter",
+		CompanyName:   "Porter Technologies, Inc.",
+		Email:         "mrp@porter.run",
 		EmailVerified: true,
 	}
 

+ 1 - 1
api/server/handlers/user/email_verify_test.go

@@ -33,7 +33,7 @@ func TestEmailVerifyInitiateSuccessful(t *testing.T) {
 	}
 
 	initiateOpts := fakeNotifier.GetSendEmailVerificationLastOpts()
-	assert.Equal(t, "test@test.it", initiateOpts.Email)
+	assert.Equal(t, "mrp@porter.run", initiateOpts.Email)
 
 	// parse the url and compare
 	parsedURL, err := url.Parse(initiateOpts.URL)

+ 8 - 5
api/server/handlers/user/login_test.go

@@ -18,7 +18,7 @@ func TestLoginUserSuccessful(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/login",
 		&types.LoginUserRequest{
-			Email:    "test@test.it",
+			Email:    "mrp@porter.run",
 			Password: "hello",
 		},
 	)
@@ -36,7 +36,10 @@ func TestLoginUserSuccessful(t *testing.T) {
 
 	expUser := &types.LoginUserResponse{
 		ID:            1,
-		Email:         "test@test.it",
+		FirstName:     "Mister",
+		LastName:      "Porter",
+		CompanyName:   "Porter Technologies, Inc.",
+		Email:         "mrp@porter.run",
 		EmailVerified: true,
 	}
 
@@ -51,7 +54,7 @@ func TestLoginUserIncorrectPassword(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/login",
 		&types.LoginUserRequest{
-			Email:    "test@test.it",
+			Email:    "mrp@porter.run",
 			Password: "hello1",
 		},
 	)
@@ -105,7 +108,7 @@ func TestLoginUserEmptyPassword(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/login",
 		&types.LoginUserRequest{
-			Email:    "test@test.it",
+			Email:    "mrp@porter.run",
 			Password: "",
 		},
 	)
@@ -157,7 +160,7 @@ func TestLoginUserFailingReadUserByEmailMethod(t *testing.T) {
 		string(types.HTTPVerbPost),
 		"/api/login",
 		&types.LoginUserRequest{
-			Email:    "test@test.it",
+			Email:    "mrp@porter.run",
 			Password: "hello",
 		},
 	)

+ 4 - 1
api/server/shared/apitest/user.go

@@ -12,7 +12,10 @@ func CreateTestUser(t *testing.T, config *config.Config, verified bool) *models.
 	hashedPw, _ := bcrypt.GenerateFromPassword([]byte("hello"), 8)
 
 	user, err := config.Repo.User().CreateUser(&models.User{
-		Email:         "test@test.it",
+		FirstName:     "Mister",
+		LastName:      "Porter",
+		CompanyName:   "Porter Technologies, Inc.",
+		Email:         "mrp@porter.run",
 		Password:      string(hashedPw),
 		EmailVerified: verified,
 	})