@takaro/modules 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -9,10 +9,10 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
|
9
9
|
async function main() {
|
|
10
10
|
// Built in modules
|
|
11
11
|
// TODO: we should probably 'export' them in CI and save it as JSON so it's consistent with the community modules
|
|
12
|
-
const modules =
|
|
12
|
+
const modules = getModules();
|
|
13
13
|
const modulesJson = JSON.stringify(modules, null, 2);
|
|
14
14
|
await writeFile('dist/modules.json', modulesJson);
|
|
15
|
-
await writeFile('../web-docs/
|
|
15
|
+
await writeFile('../web-docs/docs/modules.json', modulesJson);
|
|
16
16
|
await writeFile('../e2e/src/web-main/fixtures/modules.json', modulesJson);
|
|
17
17
|
|
|
18
18
|
// Community modules
|
|
@@ -26,7 +26,7 @@ async function main() {
|
|
|
26
26
|
|
|
27
27
|
const communityModulesJson = JSON.stringify(communityModules, null, 2);
|
|
28
28
|
await writeFile('dist/community-modules.json', communityModulesJson);
|
|
29
|
-
await writeFile('../web-docs/
|
|
29
|
+
await writeFile('../web-docs/docs/community-modules.json', communityModulesJson);
|
|
30
30
|
await writeFile('../e2e/src/web-main/fixtures/community-modules.json', communityModulesJson);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IntegrationTest, expect, IModuleTestsSetupData, modulesTestSetup, EventsAwaiter } from '@takaro/test';
|
|
2
|
+
import { HookEvents } from '../dto/index.js';
|
|
3
|
+
|
|
4
|
+
const group = 'System config - cooldown';
|
|
5
|
+
|
|
6
|
+
const customSetup = async function (this: IntegrationTest<IModuleTestsSetupData>): Promise<IModuleTestsSetupData> {
|
|
7
|
+
const setupData = await modulesTestSetup.bind(this)();
|
|
8
|
+
|
|
9
|
+
await this.client.gameserver.gameServerControllerInstallModule(setupData.gameserver.id, setupData.utilsModule.id, {
|
|
10
|
+
systemConfig: JSON.stringify({
|
|
11
|
+
commands: {
|
|
12
|
+
ping: {
|
|
13
|
+
cooldown: 60,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
return setupData;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const tests = [
|
|
22
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
23
|
+
group,
|
|
24
|
+
snapshot: false,
|
|
25
|
+
setup: customSetup,
|
|
26
|
+
name: 'Returns error when player tries to execute command that is on cooldown',
|
|
27
|
+
test: async function () {
|
|
28
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.COMMAND_EXECUTED, 1);
|
|
29
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
30
|
+
msg: '/ping',
|
|
31
|
+
playerId: this.setupData.players[0].id,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect((await events).length).to.be.eq(1);
|
|
35
|
+
|
|
36
|
+
const events2 = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CHAT_MESSAGE, 1);
|
|
37
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
38
|
+
msg: '/ping',
|
|
39
|
+
playerId: this.setupData.players[0].id,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect((await events2).length).to.be.eq(1);
|
|
43
|
+
expect((await events2)[0].data.meta.msg).to.match(
|
|
44
|
+
/This command can only be executed once every 60 seconds\. You can execute it again at /,
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
49
|
+
group,
|
|
50
|
+
snapshot: false,
|
|
51
|
+
setup: customSetup,
|
|
52
|
+
name: 'Handles cooldown when using commands in rapid succession',
|
|
53
|
+
test: async function () {
|
|
54
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CHAT_MESSAGE, 2);
|
|
55
|
+
await Promise.all([
|
|
56
|
+
this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
57
|
+
msg: '/ping',
|
|
58
|
+
playerId: this.setupData.players[0].id,
|
|
59
|
+
}),
|
|
60
|
+
this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
61
|
+
msg: '/ping',
|
|
62
|
+
playerId: this.setupData.players[0].id,
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
const sorted = (await events).sort((a, b) => a.data.meta.msg - b.data.meta.msg);
|
|
67
|
+
expect(sorted.length).to.be.eq(2);
|
|
68
|
+
expect(sorted[0].data.meta.msg).to.be.eq(
|
|
69
|
+
'You can only execute one command at a time. Please wait for the previous command to finish.',
|
|
70
|
+
);
|
|
71
|
+
expect(sorted[1].data.meta.msg).to.be.eq('Pong!');
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
describe(group, function () {
|
|
77
|
+
tests.forEach((test) => {
|
|
78
|
+
test.run();
|
|
79
|
+
});
|
|
80
|
+
});
|