cordless icon indicating copy to clipboard operation
cordless copied to clipboard

It's currently not possible to write e2e tests for Application Commands

Open TomerRon opened this issue 2 years ago • 2 comments

Background

Currently e2e tests are done by creating 2 clients:

  • One client is a cordless bot, initialized as normal with init()
  • Another client is a simple discord.js client that pretends to be a real user

In the e2e tests, these two clients "talk" to each other - for example, we subscribe the cordless bot to a messageCreate event with a condition of message.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.

TomerRon avatar Jul 16 '22 17:07 TomerRon

This library could help: https://cordejs.org/docs/ I've never used it before, but documentation looks well.

fjborquez avatar Jul 16 '22 22:07 fjborquez

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

TomerRon avatar Jul 17 '22 08:07 TomerRon