2023-10-07 11:43:12 +02:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2023-10-16 12:48:19 +02:00
|
|
|
"git.andreafazzi.eu/andrea/probo/models"
|
2023-11-13 21:01:12 +01:00
|
|
|
"git.andreafazzi.eu/andrea/probo/store"
|
2023-10-07 11:43:12 +02:00
|
|
|
"github.com/remogatto/prettytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
type collectionTestSuite struct {
|
|
|
|
prettytest.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *collectionTestSuite) TestCreateCollection() {
|
2023-11-13 21:01:12 +01:00
|
|
|
quizStore := store.NewQuizStore()
|
|
|
|
|
|
|
|
quizStore.Create(
|
|
|
|
&models.Quiz{
|
|
|
|
Question: &models.Question{Text: "Question text #tag1 #tag3."},
|
|
|
|
Answers: []*models.Answer{
|
|
|
|
{Text: "Answer 1"},
|
|
|
|
{Text: "Answer 2"},
|
|
|
|
{Text: "Answer 3"},
|
|
|
|
{Text: "Answer 4"},
|
2023-10-07 11:43:12 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
quizStore.Create(
|
|
|
|
&models.Quiz{
|
|
|
|
Question: &models.Question{Text: "Question text #tag2."},
|
|
|
|
Answers: []*models.Answer{
|
|
|
|
{Text: "Answer 1"},
|
|
|
|
{Text: "Answer 2"},
|
|
|
|
{Text: "Answer 3"},
|
|
|
|
{Text: "Answer 4"},
|
2023-10-16 12:48:19 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
quizStore.Create(
|
|
|
|
&models.Quiz{
|
|
|
|
Question: &models.Question{Text: "Question text #tag3."},
|
|
|
|
Answers: []*models.Answer{
|
|
|
|
{Text: "Answer 1"},
|
|
|
|
{Text: "Answer 2"},
|
|
|
|
{Text: "Answer 3"},
|
|
|
|
{Text: "Answer 4"},
|
|
|
|
},
|
|
|
|
})
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-20 14:14:09 +01:00
|
|
|
store, err := NewDefaultCollectionFileStore()
|
2023-11-13 21:01:12 +01:00
|
|
|
t.Nil(err)
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
c := new(models.Collection)
|
|
|
|
c.Name = "MyCollection"
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
quizStore.FilterInCollection(c, &models.Filter{
|
|
|
|
Tags: []*models.Tag{
|
|
|
|
{Name: "#tag3"},
|
|
|
|
},
|
|
|
|
})
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
_, err = store.Create(c)
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
exists, err := os.Stat(store.GetPath(c))
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
t.Nil(err)
|
|
|
|
t.Not(t.Nil(exists))
|
|
|
|
t.Equal(2, len(c.Quizzes))
|
2023-10-16 12:48:19 +02:00
|
|
|
|
2023-11-13 21:01:12 +01:00
|
|
|
defer os.Remove(store.GetPath(c))
|
2023-10-16 12:48:19 +02:00
|
|
|
}
|