Skip to content

Commit 0250e33

Browse files
committed
add tests for api-users
1 parent d38c3cb commit 0250e33

File tree

7 files changed

+124
-2
lines changed

7 files changed

+124
-2
lines changed

scraper/src/scraper/scraper_impl.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ type ScraperImpl struct {
1818

1919
// CleanPrice implements Scraper.
2020
func (s *ScraperImpl) CleanPrice(price string) ([]int, error) {
21-
// Expresión regular que captura secuencias de números (con o sin separadores de miles)
21+
// Captura numeros entre 1 y 3 digitos d{1,3} seguidos de 0 o más
22+
// grupos de 3 digitos (?:\.\d{3})* antesedidos por un punto
23+
// EJ: 123.456.789 sería \d{1,3} = 123 y (?:\.\d{3})* = .456.789
2224
re := regexp.MustCompile(`\d{1,3}(?:\.\d{3})*`)
2325

2426
// Encontrar todas las coincidencias

shared/json/response/user_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package response
33
type UserResponse struct {
44
UserID string `json:"user_id" validate:"required"`
55
Username string `json:"username" validate:"required"`
6-
Email string `json:"email" validate:"required"`
6+
Email string `json:"email" validate:"required,email"`
77
}

shared/mocks/mock_dynamodb.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package mocks
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/service/dynamodb"
5+
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
6+
"github.com/stretchr/testify/mock"
7+
)
8+
9+
type MockDynamoDB struct {
10+
dynamodbiface.DynamoDBAPI
11+
mock.Mock
12+
}
13+
14+
func (m *MockDynamoDB) Query(input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) {
15+
args := m.Called(input)
16+
return args.Get(0).(*dynamodb.QueryOutput), args.Error(1)
17+
}
18+
19+
func (m *MockDynamoDB) PutItem(input *dynamodb.PutItemInput) (*dynamodb.PutItemOutput, error) {
20+
args := m.Called(input)
21+
return args.Get(0).(*dynamodb.PutItemOutput), args.Error(1)
22+
}
23+
24+
func (m *MockDynamoDB) Scan(input *dynamodb.ScanInput) (*dynamodb.ScanOutput, error) {
25+
args := m.Called(input)
26+
return args.Get(0).(*dynamodb.ScanOutput), args.Error(1)
27+
}
28+
29+
func (m *MockDynamoDB) GetItem(input *dynamodb.GetItemInput) (*dynamodb.GetItemOutput, error) {
30+
args := m.Called(input)
31+
return args.Get(0).(*dynamodb.GetItemOutput), args.Error(1)
32+
}

shared/mocks/mock_jwtutils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package mocks
2+
3+
import "github.com/stretchr/testify/mock"
4+
5+
type MockJWTUtils struct {
6+
mock.Mock
7+
}
8+
9+
func (m *MockJWTUtils) GenerateToken(userID string) (string, error) {
10+
args := m.Called(userID)
11+
return args.String(0), args.Error(1)
12+
}

shared/mocks/mock_passwordhasher.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package mocks
2+
3+
import "github.com/stretchr/testify/mock"
4+
5+
type MockPasswordHasher struct {
6+
mock.Mock
7+
}
8+
9+
func (m *MockPasswordHasher) HashPassword(password string) (string, error) {
10+
args := m.Called(password)
11+
return args.String(0), args.Error(1)
12+
}
13+
14+
func (m *MockPasswordHasher) ComparePassword(hashedPassword, password string) error {
15+
args := m.Called(hashedPassword, password)
16+
return args.Error(0)
17+
}

shared/mocks/mocks_user_repo.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package mocks
2+
3+
import (
4+
"github.com/dieg0code/shared/models"
5+
"github.com/stretchr/testify/mock"
6+
)
7+
8+
type MockUserRepository struct {
9+
mock.Mock
10+
}
11+
12+
func (m *MockUserRepository) GetByEmail(email string) (models.User, error) {
13+
args := m.Called(email)
14+
return args.Get(0).(models.User), args.Error(1)
15+
}
16+
17+
func (m *MockUserRepository) Create(user models.User) (models.User, error) {
18+
args := m.Called(user)
19+
return args.Get(0).(models.User), args.Error(1)
20+
}
21+
22+
func (m *MockUserRepository) GetAll() ([]models.User, error) {
23+
args := m.Called()
24+
return args.Get(0).([]models.User), args.Error(1)
25+
}
26+
27+
func (m *MockUserRepository) GetByID(userID string) (models.User, error) {
28+
args := m.Called(userID)
29+
return args.Get(0).(models.User), args.Error(1)
30+
}

shared/mocks/mocks_user_service.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mocks
2+
3+
import (
4+
"github.com/dieg0code/shared/json/request"
5+
"github.com/dieg0code/shared/json/response"
6+
"github.com/dieg0code/shared/models"
7+
"github.com/stretchr/testify/mock"
8+
)
9+
10+
type MockUserService struct {
11+
mock.Mock
12+
}
13+
14+
func (m *MockUserService) RegisterUser(createUserReq request.CreateUserRequest) (models.User, error) {
15+
args := m.Called(createUserReq)
16+
return args.Get(0).(models.User), args.Error(1)
17+
}
18+
func (m *MockUserService) GetAllUsers() ([]response.UserResponse, error) {
19+
args := m.Called()
20+
return args.Get(0).([]response.UserResponse), args.Error(1)
21+
}
22+
func (m *MockUserService) GetUserByID(id string) (response.UserResponse, error) {
23+
args := m.Called(id)
24+
return args.Get(0).(response.UserResponse), args.Error(1)
25+
}
26+
func (m *MockUserService) LogInUser(logInUserReq request.LogInUserRequest) (response.LogInUserResponse, error) {
27+
args := m.Called(logInUserReq)
28+
return args.Get(0).(response.LogInUserResponse), args.Error(1)
29+
}

0 commit comments

Comments
 (0)