Open TomerRon opened 2 years ago
This library could help: https://cordejs.org/docs/ I've never used it before, but documentation looks well.
That's neat. Unfortunately it looks like this library uses the same trick I'm using here, having a bot pretend to be a real user. They have the same issue: https://github.com/cordejs/corde/issues/1026#issuecomment-1039422548
Background
Currently e2e tests are done by creating 2 clients:
init()
discord.js
client that pretends to be a real userIn the e2e tests, these two clients "talk" to each other - for example, we subscribe the cordless bot to a
messageCreate
event with a condition ofmessage.content === 'ping'
, and test the function callbacks by having the "fake user" send a ping message and assert that the cordless bot responded with a pong.Problem
With the introduction of Application Commands, it's not possible to test them with a bot pretending to be a user. This is because Bots can not interact with other Bots through commands.
For example, we might register a
/ping
command in the cordless bot. When the "fake user" sends/ping
, it will simply send it as a message and not create the interaction. So it is not possible to assert that the command works.Solution
Not really sure at the moment.
We could probably simulate a browser and login into a "real" user (with Cypress for example), but that would be cumbersome and definitely against the Discord ToS, so that's not a viable option.
Another option might be to query the Discord API to get back information about the bot's commands. We can create snapshots of the JSON response for different scenarios (e.g., no commands registered, simple commands, commands with options, etc). That still won't let us test the command handling itself (and anything involved in the process, like interactive buttons and how they are handled), but at least we can assert that the commands are registered properly.