feat: add player Names Throughout the Game UI
This commit is contained in:
@@ -98,6 +98,9 @@ static void test_sessions_commands_and_state(void) {
|
||||
assert(response.status == 200U);
|
||||
char player_2_token[33];
|
||||
token_from_response(&response, player_2_token);
|
||||
response = call(&api, HTTP_API_ROUTE_INFO, HTTP_API_GET, NULL, NULL);
|
||||
assert(response.status == 200U && strstr(response.body, "\"player1Name\":\"Alice\"") != NULL &&
|
||||
strstr(response.body, "\"player2Name\":\"Bob\"") != NULL);
|
||||
response = call(&api, HTTP_API_ROUTE_JOIN, HTTP_API_POST,
|
||||
"{\"name\":\"Watch\",\"requestedRole\":\"spectator\"}", NULL);
|
||||
assert(response.status == 200U);
|
||||
|
||||
@@ -39,9 +39,10 @@ static void test_role_views_and_golden_schema(void) {
|
||||
|
||||
assert(state_presenter_write(&state, ROLE_PLAYER_1, output, sizeof(output), &written));
|
||||
assert(written == strlen(output));
|
||||
assert(strstr(output, "{\"type\":\"state\",\"version\":9,\"gameId\":42,\"phase\":\"in_progress\",\"mode\":\"human\",\"viewer\":\"player1\",\"turn\":\"player2\",\"boards\":[\"") == output);
|
||||
assert(strstr(output, "{\"type\":\"state\",\"version\":9,\"gameId\":42,\"phase\":\"in_progress\",\"mode\":\"human\",\"viewer\":\"player1\",\"turn\":\"player2\",\"players\":[\"\",\"\"],\"boards\":[\"") == output);
|
||||
assert(board_start(output, 0)[0] == '1' && board_start(output, 0)[1] == '2' && board_start(output, 0)[2] == '3');
|
||||
assert_hidden(output, 1);
|
||||
assert(strstr(output, "\"players\":[\"\",\"\"]") != NULL);
|
||||
|
||||
assert(state_presenter_write(&state, ROLE_PLAYER_2, output, sizeof(output), &written));
|
||||
assert_hidden(output, 0);
|
||||
@@ -76,11 +77,21 @@ static void test_finished_and_failure_are_safe(void) {
|
||||
lifecycle.game.state.winner = 1U;
|
||||
lifecycle.game.state.statistics[0] = (match_statistics_t){.shots = 9U, .hits = 4U, .misses = 5U, .ships_sunk = 2U};
|
||||
lifecycle.game.state.statistics[1] = (match_statistics_t){.shots = 8U, .hits = 5U, .misses = 3U, .ships_sunk = 3U};
|
||||
lifecycle.sessions.entries[0] = (session_t){.occupied = true, .role = ROLE_PLAYER_1, .name = "Алиса"};
|
||||
lifecycle.sessions.entries[1] = (session_t){.occupied = true, .role = ROLE_PLAYER_2, .name = "Борис"};
|
||||
lifecycle.cumulative[0].wins = UINT16_MAX;
|
||||
lifecycle.cumulative[1].wins = UINT16_MAX;
|
||||
assert(state_presenter_write_lifecycle(&lifecycle, ROLE_SPECTATOR, output, sizeof(output), &written));
|
||||
assert(written < sizeof(output));
|
||||
assert(strstr(output, "\"winner\":1,\"statistics\":[[9,4,5,2],[8,5,3,3]]") != NULL);
|
||||
assert(strstr(output, "\"players\":[\"Алиса\",\"Борис\"]") != NULL);
|
||||
|
||||
memset(lifecycle.sessions.entries[0].name, 'A', kDisplayNameBytes);
|
||||
memset(lifecycle.sessions.entries[1].name, 'B', kDisplayNameBytes);
|
||||
lifecycle.sessions.entries[0].name[kDisplayNameBytes] = '\0';
|
||||
lifecycle.sessions.entries[1].name[kDisplayNameBytes] = '\0';
|
||||
assert(state_presenter_write_lifecycle(&lifecycle, ROLE_SPECTATOR, output, sizeof(output), &written));
|
||||
assert(written < sizeof(output));
|
||||
|
||||
lifecycle.game.state.statistics[0] = (match_statistics_t){UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT8_MAX};
|
||||
lifecycle.game.state.statistics[1] = (match_statistics_t){UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT8_MAX};
|
||||
|
||||
Reference in New Issue
Block a user