Skip to main content

Testing

Use the SDK testing tools to develop and verify your game without connecting it to the live QS Play portal. The debug panel helps track SDK calls and events, while mock mode lets you simulate users, authentication states, errors, locale changes, and multiplayer invitations during local development.

Debug panel​

The URL flag:

?sdk-debug=1

enables a small panel in the bottom-right corner of the page that logs every module.method call, its result or error, as well as every event — it works the same way on top of mock mode and the real portal. Clicking the panel's header collapses/expands it.

Both flags (sdk-debug and sdk-mock, see below) can be combined: ?sdk-mock=1&sdk-debug=1.

Mock mode​

If a page with QSPlaySDK is opened outside an <iframe> — for example, you simply opened the game in a separate tab during local development — the SDK automatically switches to mock mode: all methods resolve locally with test data, with no real portal behind them.

The same mode can be forced (including inside an iframe) with a URL flag:

?sdk-mock=1

Controlling the user from the console​

While the mock is in use, QSPlaySDK.__mock is available — a set of console helpers for managing state without reloading the page:

QSPlaySDK.__mock?.login("user2"); // sign in as one of the built-in presets, sends authChanged
QSPlaySDK.__mock?.login({ name: "Alex" }); // sign in as a custom user (on top of the user1 preset)
QSPlaySDK.__mock?.logout(); // sign out, sends authChanged with user: null
QSPlaySDK.__mock?.setLocale("ru"); // change the locale that game.getConfig() will return

The built-in presets are user1 ({ qsid: "ABCDEF", name: "Mock Player One", avatarUrl: null }) and user2 ({ qsid: "A1B2C3", name: "Mock Player Two", avatarUrl: null }) — handy for testing scenarios with two different players without describing the object by hand each time. The qsid of both presets has the same shape as on the portal — 6 random letters/digits (for example, C7GZE3), rather than something obviously artificial like mock-user-1.

Controlling the user via query parameters​

To get the desired state right when the page opens, without the console — convenient for links that are handed to QA, or for screenshot tests:

?sdk-mock-user= changes what the getUser method returns, and which user the page opens with right away. Accepts the values: user1, user2, logged_out (the default — as with any unrecognized value).

?sdk-mock-auth-prompt= changes what the showAuthPrompt method simulates. Accepts the values: success (the default — signs in as user1 and sends authChanged), cancelled (the player closed the login popup — nothing changes, authChanged isn't sent).

?sdk-mock-token-error= changes what the getUserToken method returns. Accepts the value 1 — then the request fails not with USER_NOT_AUTHENTICATED but as if the token backend itself had gone down (UNKNOWN), even when the user is signed in. Handy for checking that the game correctly handles that specific error code, not just "not authenticated".

?sdk-mock-invite= changes what game.getInviteParams() returns — it simulates opening the page via a link from game.inviteLink(). The value is the same base64url-JSON string that inviteLink() returns (the easiest way to get it is to call inviteLink() in mock mode and copy ?sdk-mock-invite=... from the result). An unrecognizable value silently falls back to a regular launch without an invite — getInviteParams() will return null, as if the parameter weren't there at all.

These parameters set only the initial state — after that you can keep controlling it through QSPlaySDK.__mock from the console. For example, ?sdk-mock-user=user2&sdk-mock=1 opens the game already signed in as user2.

In mock mode, user.getUserToken() returns not an arbitrary string but a structurally real JWT — three base64url segments that can be decoded with jwt.decode() or any other JWT library: inside the payload are the signed-in mock user's qsid and game_code: "mock-game", as in a real token (see User module). The signature is a fixed placeholder: it can't be verified cryptographically (there is no real portal behind the mock), and that isn't needed for local development.