2023-10-18 13:40:21 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2023-10-28 20:50:06 +02:00
|
|
|
"os"
|
2023-10-18 13:40:21 +02:00
|
|
|
"testing"
|
|
|
|
|
2023-10-28 20:50:06 +02:00
|
|
|
"git.andreafazzi.eu/andrea/probo/client"
|
|
|
|
"git.andreafazzi.eu/andrea/probo/hasher/sha256"
|
|
|
|
"git.andreafazzi.eu/andrea/probo/store/memory"
|
2023-10-18 13:40:21 +02:00
|
|
|
"github.com/remogatto/prettytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dbTestSuite struct {
|
|
|
|
prettytest.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunner(t *testing.T) {
|
|
|
|
prettytest.Run(
|
|
|
|
t,
|
|
|
|
new(dbTestSuite),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dbTestSuite) TestCreateExam() {
|
2023-10-28 20:50:06 +02:00
|
|
|
memStore := memory.NewMemoryProboCollectorStore(
|
|
|
|
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
|
|
|
|
)
|
|
|
|
memStore.CreateQuiz(
|
|
|
|
&client.CreateUpdateQuizRequest{
|
|
|
|
Quiz: &client.Quiz{
|
|
|
|
Question: &client.Question{Text: "Newly created question text with #tag1."},
|
|
|
|
Answers: []*client.Answer{
|
|
|
|
{Text: "Answer 1", Correct: true},
|
|
|
|
{Text: "Answer 2", Correct: false},
|
|
|
|
{Text: "Answer 3", Correct: false},
|
|
|
|
{Text: "Answer 4", Correct: false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
store, err := NewDBProboCollectorStore("testdata/test.sqlite", memStore)
|
|
|
|
defer os.Remove("testdata/test.sqlite")
|
|
|
|
|
2023-10-18 13:40:21 +02:00
|
|
|
t.Nil(err)
|
2023-10-28 20:50:06 +02:00
|
|
|
|
|
|
|
if !t.Failed() {
|
|
|
|
collection, err := memStore.CreateCollection(&client.CreateUpdateCollectionRequest{
|
|
|
|
Collection: &client.Collection{
|
|
|
|
Name: "Collection name",
|
|
|
|
Query: "#tag1",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
|
|
|
|
if !t.Failed() {
|
|
|
|
exam, err := store.CreateExam(&client.CreateUpdateExamRequest{
|
|
|
|
Exam: &client.Exam{
|
|
|
|
Name: "Exam",
|
|
|
|
Description: "Exam description",
|
|
|
|
CollectionID: collection.ID,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
if !t.Failed() {
|
|
|
|
t.Not(t.Nil(exam))
|
|
|
|
examFromDb, err := store.ReadExamByID(&client.ReadExamByIDRequest{ID: exam.ID})
|
|
|
|
t.Nil(err)
|
|
|
|
if !t.Failed() {
|
|
|
|
t.Equal(examFromDb.ID, exam.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-18 13:40:21 +02:00
|
|
|
}
|