fix: Preserve existing values when optional update fields are omitted (#14344)

* fix: Preserve existing values when optional update fields are omitted

* chore: Rename setDefined to fill

* chore: Use fill in users.update and teamUpdater
This commit is contained in:
Tom Moor authored and GitHub committed 2026-10-26 17:29:17 -04:00
1 parent ce439c893c
commit 9fe0c7ba2b
18 files changed
+275 -136

No files matched your search

@@ -256,6 +256,51 @@ describe("#webhookSubscriptions.update", () => {
expect(webhook.enabled).toEqual(true);
});
it("should preserve the signing secret when it is omitted", async () => {
const user = await buildAdmin();
const existingWebhook = await buildWebhookSubscription({
createdById: user.id,
teamId: user.teamId,
secret: "Test secret",
});
const res = await server.post("/api/webhookSubscriptions.update", user, {
body: {
id: existingWebhook.id,
name: "Updated webhook name",
url: existingWebhook.url,
events: existingWebhook.events,
},
});
expect(res.status).toEqual(200);
await existingWebhook.reload();
expect(existingWebhook.secret).toEqual("Test secret");
});
it("should clear the signing secret when it is empty", async () => {
const user = await buildAdmin();
const existingWebhook = await buildWebhookSubscription({
createdById: user.id,
teamId: user.teamId,
secret: "Test secret",
});
const res = await server.post("/api/webhookSubscriptions.update", user, {
body: {
id: existingWebhook.id,
name: existingWebhook.name,
url: existingWebhook.url,
events: existingWebhook.events,
secret: "",
},
});
expect(res.status).toEqual(200);
await existingWebhook.reload();
expect(existingWebhook.secret).toBeNull();
});
it("should update a webhook subscription without a signing secret", async () => {
const user = await buildAdmin();
const name = "Updated webhook name";
@@ -161,7 +161,7 @@ router.post(
url,
events: compact(events),
enabled: true,
secret: isEmpty(secret) ? undefined : secret,
secret: secret === "" ? null : secret,
});
ctx.body = {