session icon indicating copy to clipboard operation
session copied to clipboard

how to setup tests with multiple clients (and sessions)?

Open maks-io opened this issue 5 years ago • 0 comments

I am using express-session on my node backend, together with connect-mongo, and I am having multiple clients (react + react native) connecting to that backend. More end-user-ish spoken: one user can connect to my application from multiple clients (for instance via his smartphone and his tablet). I introduced some rather complex state syncing logic (incl. conflict resolution etc.), and now would like to write some Jest tests to test this.

The problem is, i would like to test sequences like the following:

  1. user logs in on smartphone
  2. user logs in on tablet
  3. user does some app action on smartphone
  4. user does some app action on tablet etc.

Since I am having automatic tests running locally (and not really multiple clients) I would like to introduce some kind of middleware that allows me to select from existing sessions (to simulate a request coming from smartphone OR from the tablet). And even requests without session (or a blank new session) would be desired.

How would I be able to simulate this?

Be aware, that i don't really want to destroy (!) a given session when switching. So when the user does something on the smartphone, and then i want to simulate a tablet action i want to keep the smartphone session of course, just remove it from the req object.

So, if i understood it correctly, I would already need to somehow "clear" the session after step 1 of the scenario described above, so that in step 2 - when simulating that the user logs in on the tablet - a new session is being created.

After step 2 i would then like to re-use these two sessions for the remaining testing steps, however i need them.

maks-io avatar Dec 11 '20 18:12 maks-io