mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-05 17:10:30 +00:00
Initial tests for location fields
This commit is contained in:
parent
64b3ac3e94
commit
a46f896c7f
1 changed files with 46 additions and 0 deletions
|
@ -290,3 +290,49 @@ func TestConvertLocationsToTree(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestLocationRepository_GetAllCustomFields(t *testing.T) {
|
||||||
|
const FIELDS_COUNT = 5
|
||||||
|
|
||||||
|
entity := useLocations(t, 1)[0]
|
||||||
|
|
||||||
|
fields := make([]LocationField, FIELDS_COUNT)
|
||||||
|
names := make([]string, FIELDS_COUNT)
|
||||||
|
values := make([]string, FIELDS_COUNT)
|
||||||
|
|
||||||
|
for i := 0; i < FIELDS_COUNT; i++ {
|
||||||
|
name := fk.Str(10)
|
||||||
|
fields[i] = LocationField{
|
||||||
|
Name: name,
|
||||||
|
Type: "text",
|
||||||
|
TextValue: fk.Str(10),
|
||||||
|
}
|
||||||
|
names[i] = name
|
||||||
|
values[i] = fields[i].TextValue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := tRepos.Locations.UpdateByGroup(context.Background(), tGroup.ID, LocationUpdate{
|
||||||
|
ID: entity.ID,
|
||||||
|
Name: entity.Name,
|
||||||
|
LocationID: entity.Location.ID,
|
||||||
|
Fields: fields,
|
||||||
|
})
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Test getting all fields
|
||||||
|
{
|
||||||
|
results, err := tRepos.Locations.GetAllCustomFieldNames(context.Background(), tGroup.ID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.ElementsMatch(t, names, results)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test getting all values from field
|
||||||
|
{
|
||||||
|
results, err := tRepos.Locations.GetAllCustomFieldValues(context.Background(), tUser.GroupID, names[0])
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.ElementsMatch(t, values[:1], results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue