Skip to content

Commit

Permalink
chore: move mocks from test dir
Browse files Browse the repository at this point in the history
  • Loading branch information
dexfs committed Apr 19, 2024
1 parent ae51c7f commit a6e0775
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 307 deletions.
97 changes: 0 additions & 97 deletions internal/application/handlers/post_handlers.go

This file was deleted.

44 changes: 0 additions & 44 deletions internal/application/handlers/user_handlers.go

This file was deleted.

87 changes: 0 additions & 87 deletions internal/application/usecases/createpost.usecase_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions internal/domain/interfaces/user_types.go

This file was deleted.

69 changes: 69 additions & 0 deletions mocks/mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package mocks

import (
"github.com/dexfs/go-twitter-clone/internal/infra/repository/inmemory"
"github.com/dexfs/go-twitter-clone/internal/post"
"github.com/dexfs/go-twitter-clone/internal/user"
"github.com/dexfs/go-twitter-clone/pkg/database"
"strconv"
)

// mocks
func MakeDb[T any]() *database.InMemoryDB[T] {
return &database.InMemoryDB[T]{}
}
func MakeInMemoryUserRepo(db *database.InMemoryDB[user.User]) user.UserRepository {
repo := repo_inmemory.NewInMemoryUserRepo(db)
return repo
}
func MakeInMemoryPostRepo(db *database.InMemoryDB[post.Post]) post.PostRepository {
repo := repo_inmemory.NewInMemoryPostRepo(db)
return repo
}
func UserSeed(db *database.InMemoryDB[user.User], amount int) []*user.User {
if amount <= 0 {
amount = 1
}
users := make([]*user.User, amount)
for i := 0; i < len(users); i++ {
username := "user" + strconv.Itoa(i)
newUser := user.NewUser(username)
db.Insert(newUser)
users[i] = newUser
}
return users
}
func PostSeed(db *database.InMemoryDB[post.Post], user *user.User, amount int) []*post.Post {
posts := make([]*post.Post, amount)
for i := 0; i < len(posts); i++ {
newPostInput := post.NewPostInput{
User: user,
Content: "post_" + strconv.Itoa(i),
}
newPost, _ := post.NewPost(newPostInput)
db.Insert(newPost)
posts[i] = newPost
}
return posts
}

type TestMocks struct {
MockUserDB *database.InMemoryDB[user.User]
MockUserSeed []*user.User
MockPostDB *database.InMemoryDB[post.Post]
MockPostsSeed []*post.Post
}

func GetTestMocks() TestMocks {
mockUserDB := MakeDb[user.User]()
mockPostDB := MakeDb[post.Post]()
mockUserSeed := UserSeed(mockUserDB, 1)
mockPostsSeed := PostSeed(mockPostDB, mockUserSeed[0], 2)

return TestMocks{
MockUserDB: mockUserDB,
MockUserSeed: mockUserSeed,
MockPostDB: mockPostDB,
MockPostsSeed: mockPostsSeed,
}
}
69 changes: 0 additions & 69 deletions tests/mocks/mocks.go

This file was deleted.

0 comments on commit a6e0775

Please sign in to comment.