fix: Accepts empty string for the icon prop to remove it (#3760)

This commit is contained in:
Bruno Quaresma
2022-08-30 18:48:03 +00:00
committed by GitHub
parent 1dc0485027
commit f037aad456
2 changed files with 21 additions and 3 deletions
-3
View File
@@ -470,9 +470,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
if desc == "" {
desc = template.Description
}
if icon == "" {
icon = template.Icon
}
if minAutostartInterval == 0 {
minAutostartInterval = time.Duration(template.MinAutostartInterval)
}
+21
View File
@@ -481,6 +481,27 @@ func TestPatchTemplateMeta(t *testing.T) {
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
})
t.Run("RemoveIcon", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
ctr.Icon = "/icons/code.png"
})
req := codersdk.UpdateTemplateMeta{
Icon: "",
}
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
updated, err := client.UpdateTemplateMeta(ctx, template.ID, req)
require.NoError(t, err)
assert.Equal(t, updated.Icon, "")
})
}
func TestDeleteTemplate(t *testing.T) {