57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package integration
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
"gitea.pena/SQuiz/common/model"
|
|
"gitea.pena/SQuiz/common/repository/answer"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Test_CreateAnswers(t *testing.T) {
|
|
pool, err := sql.Open("postgres", "host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable")
|
|
assert.NoError(t, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second)
|
|
defer cancel()
|
|
|
|
err = pool.PingContext(timeoutCtx)
|
|
assert.NoError(t, err)
|
|
|
|
queries := sqlcgen.New(pool)
|
|
ansRepo := answer.NewAnswerRepository(answer.Deps{
|
|
Queries: queries,
|
|
Pool: pool,
|
|
})
|
|
|
|
ids, errs := ansRepo.CreateAnswers(ctx, []model.Answer{
|
|
{
|
|
Content: "test",
|
|
QuizId: 15259,
|
|
QuestionId: 15259,
|
|
Fingerprint: "adsfadfd",
|
|
Session: "afdfdfaffa",
|
|
Result: false,
|
|
Email: "test@gmail.com",
|
|
Device: "ans.Device",
|
|
DeviceType: "ans.DeviceType",
|
|
IP: "ans.IP",
|
|
Browser: "ans.Browser",
|
|
OS: "ans.OS",
|
|
Start: false,
|
|
Utm: make(model.UTMSavingMap),
|
|
},
|
|
}, "afdfdfaffa", "adsfadfd", 15259)
|
|
if len(errs) > 0 {
|
|
fmt.Println(errs)
|
|
}
|
|
|
|
fmt.Println(ids)
|
|
}
|