42 lines
1 KiB
Go
42 lines
1 KiB
Go
package models_test
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.cacert.org/cacert-boardvoting/internal"
|
|
"git.cacert.org/cacert-boardvoting/internal/models"
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDecisionModel_Create(t *testing.T) {
|
|
testDir := t.TempDir()
|
|
|
|
db, err := sql.Open("sqlite3", path.Join(testDir, "test.sqlite"))
|
|
require.NoError(t, err)
|
|
|
|
dbx := sqlx.NewDb(db, "sqlite3")
|
|
|
|
logger := log.New(os.Stdout, "", log.LstdFlags)
|
|
|
|
err = internal.InitializeDb(dbx.DB, logger)
|
|
require.NoError(t, err)
|
|
|
|
dm := models.DecisionModel{DB: dbx, InfoLog: logger}
|
|
|
|
v := &models.Voter{
|
|
ID: 1, // sqlite does not check referential integrity. Might fail with a foreign key index.
|
|
Name: "test voter",
|
|
Reminder: "test+voter@example.com",
|
|
}
|
|
|
|
id, err := dm.Create(v, models.VoteTypeMotion, "test motion", "I move that we should test more", time.Now(), time.Now().AddDate(0, 0, 7))
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, id)
|
|
}
|