2024-12-18 18:52:38 +00:00
|
|
|
package name_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"gotemplate/internal/database/repository"
|
|
|
|
|
"gotemplate/internal/document"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSync(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
db, err := pgxmock.NewConn()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer db.Close(ctx)
|
|
|
|
|
|
|
|
|
|
queries := repository.New(db)
|
|
|
|
|
svc := document.New(ctx, queries)
|
|
|
|
|
doc := document.Document{
|
|
|
|
|
ID: "1",
|
|
|
|
|
Name: "document_name",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.ExpectExec("INSERT INTO names (name) VALUES ($1)")
|
|
|
|
|
|
|
|
|
|
err = svc.Sync(ctx, doc)
|
|
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
}
|