Add support for removing custom field keys (#6362)

This commit is contained in:
WithoutPants
2025-12-04 07:28:06 +11:00
committed by GitHub
parent ee61fc879b
commit 0bc4faef2a
6 changed files with 98 additions and 11 deletions

View File

@@ -64,6 +64,18 @@ func TestSetCustomFields(t *testing.T) {
}),
false,
},
{
"valid remove",
models.CustomFieldsInput{
Remove: []string{"real"},
},
func() map[string]interface{} {
m := getPerformerCustomFields(performerIdx)
delete(m, "real")
return m
}(),
false,
},
{
"leading space full",
models.CustomFieldsInput{
@@ -144,16 +156,38 @@ func TestSetCustomFields(t *testing.T) {
nil,
true,
},
{
"invalid remove full",
models.CustomFieldsInput{
Full: map[string]interface{}{
"key": "value",
},
Remove: []string{"key"},
},
nil,
true,
},
{
"invalid remove partial",
models.CustomFieldsInput{
Partial: map[string]interface{}{
"real": float64(4.56),
},
Remove: []string{"real"},
},
nil,
true,
},
}
// use performer custom fields store
store := db.Performer
id := performerIDs[performerIdx]
assert := assert.New(t)
for _, tt := range tests {
runWithRollbackTxn(t, tt.name, func(t *testing.T, ctx context.Context) {
assert := assert.New(t)
err := store.SetCustomFields(ctx, id, tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("SetCustomFields() error = %v, wantErr %v", err, tt.wantErr)