fix: move testdb/testuser to a mock dir to be clearer

This commit is contained in:
Muyao CHEN 2024-10-12 18:52:27 +02:00
parent addddb152a
commit 79739e3751
3 changed files with 7 additions and 6 deletions

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package usecase
package repomock
import "context"

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package usecase
package repomock
import (
"context"

View File

@ -27,13 +27,14 @@ import (
"testing"
"git.vinchent.xyz/vinchent/howmuch/internal/howmuch/model"
"git.vinchent.xyz/vinchent/howmuch/internal/howmuch/usecase/usecase/repomock"
"github.com/stretchr/testify/assert"
)
func TestCreateUser(t *testing.T) {
t.Run("normal create", func(t *testing.T) {
ctx := context.Background()
userUsecase := NewUserUsecase(&TestUserRepository{}, &TestDBRepository{})
userUsecase := NewUserUsecase(&repomock.TestUserRepository{}, &repomock.TestDBRepository{})
input := &model.User{
Email: "a@b.c",
FirstName: "James",
@ -50,7 +51,7 @@ func TestCreateUser(t *testing.T) {
t.Run("duplicate create", func(t *testing.T) {
ctx := context.Background()
userUsecase := NewUserUsecase(&TestUserRepository{}, &TestDBRepository{})
userUsecase := NewUserUsecase(&repomock.TestUserRepository{}, &repomock.TestDBRepository{})
input := &model.User{
Email: "duplicate@error.com",
FirstName: "James",
@ -77,7 +78,7 @@ func TestUserExist(t *testing.T) {
{"query error", &model.User{
Email: "query@error.com",
Password: "strongHashed",
}, UserTestDummyErr, false},
}, repomock.UserTestDummyErr, false},
{"user doesn not exist", &model.User{
Email: "inexist@error.com",
Password: "strongHashed",
@ -90,7 +91,7 @@ func TestUserExist(t *testing.T) {
for _, tst := range testCases {
ctx := context.Background()
userUsecase := NewUserUsecase(&TestUserRepository{}, &TestDBRepository{})
userUsecase := NewUserUsecase(&repomock.TestUserRepository{}, &repomock.TestDBRepository{})
got, err := userUsecase.Exist(ctx, tst.User)
assert.ErrorIs(t, err, tst.ExpErr)