Skip to content

Commit

Permalink
users test
Browse files Browse the repository at this point in the history
  • Loading branch information
source-Alexander-Rudenko committed Dec 18, 2024
1 parent 8cd175a commit 2adb978
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions internal/user/repository/users_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package userRepository

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"kudago/internal/models"
)

func TestNilIfEmpty(t *testing.T) {
// Тестируем функцию NilIfEmpty
tests := []struct {
input string
expected *string
}{
{"", nil},
{"non-empty", stringPtr("non-empty")},
}

for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
actual := NilIfEmpty(tt.input)
assert.Equal(t, tt.expected, actual)
})
}
}

func TestToDomainUser(t *testing.T) {
// Тестируем функцию ToDomainUser
tests := []struct {
input UserInfo
expected models.User
}{
{
input: UserInfo{
ID: 1,
Username: "user1",
Email: "[email protected]",
ImageURL: stringPtr("http://example.com/avatar1"),
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
},
expected: models.User{
ID: 1,
Username: "user1",
Email: "[email protected]",
ImageURL: "http://example.com/avatar1",
},
},
{
input: UserInfo{
ID: 2,
Username: "user2",
Email: "[email protected]",
ImageURL: nil,
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
},
expected: models.User{
ID: 2,
Username: "user2",
Email: "[email protected]",
ImageURL: "",
},
},
}

for _, tt := range tests {
t.Run(tt.input.Username, func(t *testing.T) {
actual := ToDomainUser(tt.input)
assert.Equal(t, tt.expected, actual)
})
}
}

func stringPtr(s string) *string {
return &s
}

0 comments on commit 2adb978

Please sign in to comment.