chore(task): add test to check if a task's reminders are duplicated
This commit is contained in:
parent
f2b4e9260b
commit
40411e4100
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"xorm.io/builder"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
@ -102,3 +103,10 @@ func AssertMissing(t *testing.T, table string, values map[string]interface{}) {
|
|||||||
assert.NoError(t, err, fmt.Sprintf("Failed to assert entries don't exist in db, error was: %s", err))
|
assert.NoError(t, err, fmt.Sprintf("Failed to assert entries don't exist in db, error was: %s", err))
|
||||||
assert.False(t, exists, fmt.Sprintf("Entries %v exist in table %s", values, table))
|
assert.False(t, exists, fmt.Sprintf("Entries %v exist in table %s", values, table))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertCount checks if a number of entries exists in the database
|
||||||
|
func AssertCount(t *testing.T, table string, where builder.Cond, count int64) {
|
||||||
|
dbCount, err := x.Table(table).Where(where).Count()
|
||||||
|
assert.NoError(t, err, fmt.Sprintf("Failed to assert count in db, error was: %s", err))
|
||||||
|
assert.Equal(t, count, dbCount, fmt.Sprintf("Found %d entries instead of expected %d in table %s", dbCount, count, table))
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
"xorm.io/builder"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/events"
|
"code.vikunja.io/api/pkg/events"
|
||||||
@ -367,6 +368,27 @@ func TestTask_Update(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(3), task.Index)
|
assert.Equal(t, int64(3), task.Index)
|
||||||
})
|
})
|
||||||
|
t.Run("the same date multiple times should be saved once", func(t *testing.T) {
|
||||||
|
db.LoadAndAssertFixtures(t)
|
||||||
|
s := db.NewSession()
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
task := &Task{
|
||||||
|
ID: 1,
|
||||||
|
Title: "test",
|
||||||
|
Reminders: []time.Time{
|
||||||
|
time.Unix(1674745156, 0),
|
||||||
|
time.Unix(1674745156, 223),
|
||||||
|
},
|
||||||
|
ListID: 1,
|
||||||
|
}
|
||||||
|
err := task.Update(s, u)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = s.Commit()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
db.AssertCount(t, "task_reminders", builder.Eq{"task_id": 1}, 1)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTask_Delete(t *testing.T) {
|
func TestTask_Delete(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user