From 6455ee176f9d030342350b3a131f105653732701 Mon Sep 17 00:00:00 2001 From: Niek Candaele Date: Wed, 18 Dec 2024 21:35:14 +0100 Subject: [PATCH] fix: reinstalling a module now correctly updates config like before --- packages/app-api/src/service/Module/index.ts | 9 ++ .../__tests__/bugRepros.integration.test.ts | 88 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/packages/app-api/src/service/Module/index.ts b/packages/app-api/src/service/Module/index.ts index 7508b10fa..e0385dc4a 100644 --- a/packages/app-api/src/service/Module/index.ts +++ b/packages/app-api/src/service/Module/index.ts @@ -448,6 +448,15 @@ export class ModuleService extends TakaroService({ + group, + snapshot: false, + name: 'Bug repro: command code not updated after tag change', + setup: modulesTestSetup, + test: async function () { + const mod = ( + await this.client.module.moduleControllerCreate({ + name: 'Test module', + }) + ).data.data; + const createdCommand = await this.client.command.commandControllerCreate({ + name: 'testcmd', + versionId: mod.latestVersion.id, + trigger: 'test', + function: `import { data, takaro } from '@takaro/helpers'; + async function main() { + const { player } = data; + await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, { + message: 'hello world', + }); + } + await main();`, + }); + + const tagRes1 = await this.client.module.moduleVersionControllerTagVersion({ + moduleId: mod.id, + tag: '0.0.1', + }); + + await this.client.module.moduleInstallationsControllerInstallModule({ + gameServerId: this.setupData.gameserver.id, + versionId: tagRes1.data.data.id, + userConfig: JSON.stringify({}), + systemConfig: JSON.stringify({}), + }); + + const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(GameEvents.CHAT_MESSAGE, 1); + + await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, { + msg: '/test', + playerId: this.setupData.players[0].id, + }); + + expect((await events).length).to.be.eq(1); + expect((await events)[0].data.meta.msg).to.be.eq('hello world'); + + // Update the command + await this.client.command.commandControllerUpdate(createdCommand.data.data.id, { + function: `import { data, takaro } from '@takaro/helpers'; + async function main() { + const { player } = data; + await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, { + message: 'goodbye world', + }); + } + await main();`, + }); + + const tagRes2 = await this.client.module.moduleVersionControllerTagVersion({ + moduleId: mod.id, + tag: '0.0.2', + }); + + await this.client.module.moduleInstallationsControllerInstallModule({ + gameServerId: this.setupData.gameserver.id, + versionId: tagRes2.data.data.id, + userConfig: JSON.stringify({}), + systemConfig: JSON.stringify({}), + }); + + const eventsAfter = (await new EventsAwaiter().connect(this.client)).waitForEvents(GameEvents.CHAT_MESSAGE, 1); + + await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, { + msg: '/test', + playerId: this.setupData.players[0].id, + }); + + expect((await eventsAfter).length).to.be.eq(1); + expect((await eventsAfter)[0].data.meta.msg).to.be.eq('goodbye world'); + }, + }), ]; describe(group, function () {