Skip to content

Commit

Permalink
Merge pull request ion232#48 from yzoug/zoug/fix/deserialize-gameeven…
Browse files Browse the repository at this point in the history
…tplayer-ai

Make fields optional in GameEventPlayer
  • Loading branch information
ion232 authored Jan 30, 2024
2 parents a2d6330 + a5165bf commit b49bf0a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/model/board/stream/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub struct OpponentGone {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GameEventPlayer {
pub id: String,
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ai_level: Option<u32>,
pub name: String,
pub name: Option<String>,
// This field can be null according to the openapi spec.
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
35 changes: 35 additions & 0 deletions tests/data/response/game_full_ai.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"id": "4JurXGpQ",
"variant": {
"key": "standard",
"name": "Standard",
"short": "Std"
},
"speed": "correspondence",
"perf": {
"name": "Correspondance"
},
"rated": false,
"createdAt": 1706471805992,
"white": {
"id": "saintmau46",
"name": "saintmau46",
"title": null,
"rating": 1500,
"provisional": true
},
"black": {
"aiLevel": 1
},
"initialFen": "startpos",
"type": "gameFull",
"state": {
"type": "gameState",
"moves": "",
"wtime": 2147483647,
"btime": 2147483647,
"winc": 0,
"binc": 0,
"status": "started"
}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/response_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn board_event_stream() {

#[test]
pub fn board_game_stream() {
test_response_model::<board::stream::game::Event>("game_full");
test_response_model::<board::stream::game::Event>("game_full_humans");
test_response_model::<board::stream::game::Event>("game_state");
test_response_model::<board::stream::game::Event>("game_state_resign");
test_response_model::<board::stream::game::Event>("chat_line");
Expand All @@ -39,6 +39,7 @@ pub fn board_game_stream() {
#[test]
pub fn challenge_ai() {
test_response_model::<games::stream::moves::Move>("challenge_ai");
test_response_model::<board::stream::game::Event>("game_full_ai");
}

#[test]
Expand Down

0 comments on commit b49bf0a

Please sign in to comment.