feat: implement safe leave, profile reset, and full game reset semantics
This commit is contained in:
@@ -186,9 +186,36 @@ static void test_sessions_commands_and_state(void) {
|
||||
expect_code(&response, 503U, "SERVER_BUSY");
|
||||
}
|
||||
|
||||
static void test_recovery_routes(void) {
|
||||
application_t application;
|
||||
test_random_t random = {.value = 31U};
|
||||
http_api_t api = new_api(&application, &random);
|
||||
http_api_response_t response = call(&api, HTTP_API_ROUTE_JOIN, HTTP_API_POST,
|
||||
"{\"name\":\"Alice\",\"requestedRole\":\"player1\"}", NULL);
|
||||
char player_token[33]; token_from_response(&response, player_token);
|
||||
char command[96];
|
||||
snprintf(command, sizeof(command), "{\"token\":\"%s\",\"gameId\":1}", player_token);
|
||||
response = call(&api, HTTP_API_ROUTE_LEAVE, HTTP_API_POST, command, NULL);
|
||||
assert(response.status == 200U && strstr(response.body, "session_left") != NULL);
|
||||
response = call(&api, HTTP_API_ROUTE_LEAVE, HTTP_API_POST, command, NULL);
|
||||
assert(response.status == 200U && strstr(response.body, "session_left") != NULL);
|
||||
response = call(&api, HTTP_API_ROUTE_JOIN, HTTP_API_POST,
|
||||
"{\"name\":\"Alice\",\"requestedRole\":\"player1\"}", NULL);
|
||||
token_from_response(&response, player_token);
|
||||
snprintf(command, sizeof(command), "{\"token\":\"%s\",\"gameId\":1}", player_token);
|
||||
response = call(&api, HTTP_API_ROUTE_RESET, HTTP_API_POST, command, NULL);
|
||||
assert(response.status == 200U && strstr(response.body, "game_reset") != NULL);
|
||||
response = call(&api, HTTP_API_ROUTE_STATE, HTTP_API_GET, NULL, player_token);
|
||||
assert(response.status == 401U && strstr(response.body, "SESSION_INVALIDATED") != NULL && strstr(response.body, "game_reset") != NULL);
|
||||
response = call(&api, HTTP_API_ROUTE_RESET, HTTP_API_POST,
|
||||
"{\"token\":\"00000000000000000000000000000000\",\"gameId\":1}", NULL);
|
||||
assert(response.status == 200U && strstr(response.body, "game_reset") != NULL);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_public_routes_and_parse_limits();
|
||||
test_sessions_commands_and_state();
|
||||
test_recovery_routes();
|
||||
puts("http api tests passed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user