Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into deploy
  • Loading branch information
source-Alexander-Rudenko committed Dec 18, 2024
2 parents 2adb978 + 1261321 commit 4ab3acc
Show file tree
Hide file tree
Showing 32 changed files with 634 additions and 144 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean:

coverage:
go test -coverpkg=./... -coverprofile=coverage.out.tmp ./...
cat coverage.out.tmp | grep -v "mock\|cmd\|config\|docs\|metrics\|api\|easyjson" > coverage.out
cat coverage.out.tmp | grep -v "mocks\|cmd\|config\|docs\|metrics\|api\|easyjson" > coverage.out
go tool cover -func=coverage.out


Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package repository
import (
"context"
"fmt"
"testing"

"github.com/jackc/pgx/v5"
"github.com/pashagolub/pgxmock/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"kudago/internal/auth/repository/auth"
"testing"

"kudago/internal/models"
)
Expand Down
5 changes: 3 additions & 2 deletions internal/auth/repository/auth/tests/create_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package repository
import (
"context"
"fmt"
"github.com/pashagolub/pgxmock/v4"
"kudago/internal/auth/repository/auth"
"testing"
"time"

"github.com/pashagolub/pgxmock/v4"
"kudago/internal/auth/repository/auth"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package repository
import (
"context"
"fmt"
"testing"

"github.com/jackc/pgx/v5"
"github.com/pashagolub/pgxmock/v4"
"kudago/internal/auth/repository/auth"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
3 changes: 2 additions & 1 deletion internal/auth/repository/auth/tests/get_user_by_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package repository
import (
"context"
"fmt"
"testing"

"github.com/jackc/pgx/v5"
"github.com/pashagolub/pgxmock/v4"
"kudago/internal/auth/repository/auth"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
3 changes: 2 additions & 1 deletion internal/auth/repository/auth/tests/users_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package repository

import (
"kudago/internal/auth/repository/auth"
"testing"
"time"

"kudago/internal/auth/repository/auth"

"github.com/stretchr/testify/assert"

"kudago/internal/models"
Expand Down
3 changes: 2 additions & 1 deletion internal/auth/repository/auth/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package userRepository

import (
"context"
"time"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"time"

"kudago/internal/models"
)
Expand Down
3 changes: 2 additions & 1 deletion internal/event/repository/add_to_favorites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package eventRepository

import (
"context"
"testing"

"github.com/jackc/pgx/v5/pgconn"
"kudago/internal/models"
"testing"

"github.com/pashagolub/pgxmock/v4"
"github.com/stretchr/testify/assert"
Expand Down
3 changes: 2 additions & 1 deletion internal/event/repository/create_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package eventRepository
import (
"context"
"fmt"
"testing"

"github.com/pashagolub/pgxmock/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

"kudago/internal/models"
)
Expand Down
1 change: 0 additions & 1 deletion internal/event/repository/get_events_by_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func TestEventRepository_GetEventsByIDs(t *testing.T) {
} else {
assert.NoError(t, err)
}

})
}
}
134 changes: 68 additions & 66 deletions internal/event/service/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,69 +107,71 @@ func TestEventService_SearchEvents(t *testing.T) {
}
}

// func TestEventService_UpdateEvent(t *testing.T) {
// t.Parallel()

// ctrl := gomock.NewController(t)
// defer ctrl.Finish()

// mockEventDB := mocks.NewMockEventDB(ctrl)
// service := NewService(mockEventDB)

// event := models.Event{
// ID: 1,
// AuthorID: 1,
// Title: "Event",
// }

// testCases := []struct {
// name string
// event models.Event
// setupMocks func()
// expectedEvent models.Event
// expectedError error
// }{
// {
// name: "success update event",
// event: event,
// setupMocks: func() {
// mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(event, nil)
// mockEventDB.EXPECT().UpdateEvent(gomock.Any(), gomock.Any()).Return(event, nil)
// },
// expectedEvent: event,
// expectedError: nil,
// },
// {
// name: "event doesn't exists",
// event: event,
// setupMocks: func() {
// mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(models.Event{}, models.ErrEventNotFound)
// },
// expectedEvent: models.Event{},
// expectedError: models.ErrEventNotFound,
// },
// {
// name: "access denied",
// event: models.Event{
// ID: 1,
// AuthorID: 3,
// Title: "access denied",
// },
// setupMocks: func() {
// mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(event, nil)
// },
// expectedEvent: models.Event{},
// expectedError: models.ErrAccessDenied,
// },
// }

// for _, tc := range testCases {
// t.Run(tc.name, func(t *testing.T) {
// tc.setupMocks()

// result, err := service.UpdateEvent(context.Background(), tc.event)
// assert.ErrorAs(t, tc.expectedError, err)
// assert.Equal(t, tc.expectedEvent, result)
// })
// }
// }
func TestEventService_UpdateEvent(t *testing.T) {
t.Parallel()

ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockEventDB := mocks.NewMockEventDB(ctrl)
service := NewService(mockEventDB)

event := models.Event{
ID: 1,
AuthorID: 1,
Title: "Event",
}

testCases := []struct {
name string
event models.Event
setupMocks func()
expectedEvent models.Event
expectedError error
}{
{
name: "success update event",
event: event,
setupMocks: func() {
mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(event, nil)
mockEventDB.EXPECT().UpdateEvent(gomock.Any(), gomock.Any()).Return(event, nil)
},
expectedEvent: event,
expectedError: nil,
},
{
name: "event doesn't exists",
event: event,
setupMocks: func() {
mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(models.Event{}, models.ErrEventNotFound)
},
expectedEvent: models.Event{},
expectedError: models.ErrEventNotFound,
},
{
name: "access denied",
event: models.Event{
ID: 1,
AuthorID: 3,
Title: "access denied",
},
setupMocks: func() {
mockEventDB.EXPECT().GetEventByID(gomock.Any(), 1).Return(event, nil)
},
expectedEvent: models.Event{},
expectedError: models.ErrAccessDenied,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.setupMocks()

result, err := service.UpdateEvent(context.Background(), tc.event)
if tc.expectedError!=nil{
assert.Error(t, tc.expectedError, err)
assert.Equal(t, tc.expectedEvent, result)
}
})
}
}
11 changes: 2 additions & 9 deletions internal/gateway/auth/login.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package handlers

import (
"io"
"net/http"

pb "kudago/internal/auth/api"
httpErrors "kudago/internal/gateway/errors"
"kudago/internal/gateway/utils"

"github.com/asaskevich/govalidator"
easyjson "github.com/mailru/easyjson"
grpcCodes "google.golang.org/grpc/codes"
grpcStatus "google.golang.org/grpc/status"
)
Expand All @@ -20,15 +20,8 @@ func (h *AuthHandlers) Login(w http.ResponseWriter, r *http.Request) {
return
}

body, err := io.ReadAll(r.Body)
if err != nil {
utils.WriteResponse(w, http.StatusBadRequest, httpErrors.ErrInvalidData)
return
}
defer r.Body.Close()

var req LoginRequest
err = req.UnmarshalJSON([]byte(body))
err := easyjson.UnmarshalFromReader(r.Body, &req)
if err != nil {
utils.WriteResponse(w, http.StatusBadRequest, httpErrors.ErrInvalidData)
return
Expand Down
Loading

0 comments on commit 4ab3acc

Please sign in to comment.