mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-28 17:56:29 +00:00
0cbe516ca3
* rough implementation of WS based event system for server side notifications of mutation
* fix test construction
* fix deadlock on event bus
* disable linter error
* add item mutation events
* remove old event bus code
* refactor event system to use composables
* refresh items table when new item is added
* fix create form errors
* cleanup unnecessary calls
* fix importer erorrs + limit fn calls on import
Former-commit-id: 2cbcc8bb1d
102 lines
2.4 KiB
Go
102 lines
2.4 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func labelFactory() LabelCreate {
|
|
return LabelCreate{
|
|
Name: fk.Str(10),
|
|
Description: fk.Str(100),
|
|
}
|
|
}
|
|
|
|
func useLabels(t *testing.T, len int) []LabelOut {
|
|
t.Helper()
|
|
|
|
labels := make([]LabelOut, len)
|
|
for i := 0; i < len; i++ {
|
|
itm := labelFactory()
|
|
|
|
item, err := tRepos.Labels.Create(context.Background(), tGroup.ID, itm)
|
|
assert.NoError(t, err)
|
|
labels[i] = item
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
for _, item := range labels {
|
|
_ = tRepos.Labels.delete(context.Background(), item.ID)
|
|
}
|
|
})
|
|
|
|
return labels
|
|
}
|
|
|
|
func TestLabelRepository_Get(t *testing.T) {
|
|
labels := useLabels(t, 1)
|
|
label := labels[0]
|
|
|
|
// Get by ID
|
|
foundLoc, err := tRepos.Labels.GetOne(context.Background(), label.ID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, label.ID, foundLoc.ID)
|
|
}
|
|
|
|
func TestLabelRepositoryGetAll(t *testing.T) {
|
|
useLabels(t, 10)
|
|
|
|
all, err := tRepos.Labels.GetAll(context.Background(), tGroup.ID)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, all, 10)
|
|
}
|
|
|
|
func TestLabelRepository_Create(t *testing.T) {
|
|
loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory())
|
|
assert.NoError(t, err)
|
|
|
|
// Get by ID
|
|
foundLoc, err := tRepos.Labels.GetOne(context.Background(), loc.ID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, loc.ID, foundLoc.ID)
|
|
|
|
err = tRepos.Labels.delete(context.Background(), loc.ID)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLabelRepository_Update(t *testing.T) {
|
|
loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory())
|
|
assert.NoError(t, err)
|
|
|
|
updateData := LabelUpdate{
|
|
ID: loc.ID,
|
|
Name: fk.Str(10),
|
|
Description: fk.Str(100),
|
|
}
|
|
|
|
update, err := tRepos.Labels.UpdateByGroup(context.Background(), tGroup.ID, updateData)
|
|
assert.NoError(t, err)
|
|
|
|
foundLoc, err := tRepos.Labels.GetOne(context.Background(), loc.ID)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, update.ID, foundLoc.ID)
|
|
assert.Equal(t, update.Name, foundLoc.Name)
|
|
assert.Equal(t, update.Description, foundLoc.Description)
|
|
|
|
err = tRepos.Labels.delete(context.Background(), loc.ID)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLabelRepository_Delete(t *testing.T) {
|
|
loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory())
|
|
assert.NoError(t, err)
|
|
|
|
err = tRepos.Labels.delete(context.Background(), loc.ID)
|
|
assert.NoError(t, err)
|
|
|
|
_, err = tRepos.Labels.GetOne(context.Background(), loc.ID)
|
|
assert.Error(t, err)
|
|
}
|