Skip to content

Commit

Permalink
fix: reinstalling a module now correctly updates config like before
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Dec 18, 2024
1 parent dae5036 commit 6455ee1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/app-api/src/service/Module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ export class ModuleService extends TakaroService<ModuleModel, ModuleOutputDTO, M
installDto.userConfig = JSON.stringify(modUserConfig);
installDto.systemConfig = JSON.stringify(modSystemConfig);

// If this module is already installed, we'll uninstall it first
const existingInstallation = await this.getInstalledModules({
gameserverId: installDto.gameServerId,
moduleId: versionToInstall.moduleId,
});
if (existingInstallation.length) {
await this.uninstallModule(existingInstallation[0].id);
}

const installation = await this.repo.installModule(installDto);
await this.cronjobService().syncModuleCronjobs(installation);

Expand Down
88 changes: 88 additions & 0 deletions packages/lib-modules/src/__tests__/bugRepros.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,94 @@ const tests = [
expect(result.reason).to.include('SyntaxError: Unexpected end of input.');
},
}),
/**
* Create a module with a version and command that returns a 'hello world' message and tag it
* Install the module and trigger the command
* Then, edit the command so it returns a 'goodbye world' message and tag the module again
* Trigger the command again and check if the message is 'goodbye world' *
*/
new IntegrationTest<IModuleTestsSetupData>({
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 () {
Expand Down

0 comments on commit 6455ee1

Please sign in to comment.