diff --git a/extensions/discord/src/internal/client.test.ts b/extensions/discord/src/internal/client.test.ts index b6cc0629aec..7fc185c9b3b 100644 --- a/extensions/discord/src/internal/client.test.ts +++ b/extensions/discord/src/internal/client.test.ts @@ -204,6 +204,63 @@ describe("Client.deployCommands", () => { expect(deleteRequest).not.toHaveBeenCalled(); }); + it("patches changed option localization maps", async () => { + const client = createInternalTestClient([ + createTestCommand({ + name: "one", + options: [ + { + type: 3, + name: "value", + name_localizations: { de: "wert" }, + description: "Value", + description_localizations: { de: "Wert" }, + }, + ], + }), + ]); + const get = vi.fn(async () => [ + { + id: "cmd1", + application_id: "app1", + type: ApplicationCommandType.ChatInput, + name: "one", + description: "one command", + options: [ + { + type: 3, + name: "value", + name_localizations: { de: "alter-wert" }, + description: "Value", + description_localizations: { de: "Alter Wert" }, + }, + ], + }, + ]); + const patch = vi.fn(async () => undefined); + const post = vi.fn(async () => undefined); + const deleteRequest = vi.fn(async () => undefined); + attachRestMock(client, { get, patch, post, delete: deleteRequest }); + + await client.deployCommands({ mode: "reconcile" }); + + expect(patch).toHaveBeenCalledWith( + Routes.applicationCommand("app1", "cmd1"), + expect.objectContaining({ + body: expect.objectContaining({ + options: [ + expect.objectContaining({ + name_localizations: { de: "wert" }, + description_localizations: { de: "Wert" }, + }), + ], + }), + }), + ); + expect(post).not.toHaveBeenCalled(); + expect(deleteRequest).not.toHaveBeenCalled(); + }); + it("skips command deploy when the serialized command set is unchanged", async () => { const client = createInternalTestClient([createTestCommand({ name: "one" })]); const get = vi.fn(async () => []); diff --git a/extensions/discord/src/internal/command-deploy.ts b/extensions/discord/src/internal/command-deploy.ts index 11a815637e4..526e34c1e1a 100644 --- a/extensions/discord/src/internal/command-deploy.ts +++ b/extensions/discord/src/internal/command-deploy.ts @@ -175,14 +175,12 @@ function comparableCommand(value: unknown): unknown { } const unorderedCommandArrayFields = new Set(["channel_types", "contexts", "integration_types"]); -const subcommandOptionOnlyFields = new Set([ +const optionComparisonOmittedFields = new Set([ "contexts", "default_member_permissions", "description_localized", - "description_localizations", "integration_types", "name_localized", - "name_localizations", ]); function stableComparableObject(value: unknown, path: string[] = []): unknown { @@ -210,7 +208,7 @@ function stableComparableObject(value: unknown, path: string[] = []): unknown { if (entry === undefined) { return false; } - if (path.includes("options") && subcommandOptionOnlyFields.has(key)) { + if (path.includes("options") && optionComparisonOmittedFields.has(key)) { return false; } if ((key === "required" || key === "autocomplete") && entry === false) {