From 96f8e36c97d9f7549a9a2055ce3be475c3b3e971 Mon Sep 17 00:00:00 2001 From: Artus Date: Mon, 15 Jul 2019 15:25:49 +0200 Subject: [PATCH] adds test --- lootalot_db/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index c4b149d..f6442b3 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -272,6 +272,26 @@ mod tests { assert_eq!(group.name, "Groupe".to_string()); } + #[test] + fn test_player_updates_wealth() { + let conn = test_connection(); + DbApi::with_conn(&conn).as_admin() + .add_player("PlayerName".to_string(), 403.21) + .unwrap(); + let diff = DbApi::with_conn(&conn).as_player(1) + .update_wealth(-401.21).unwrap() + .response.unwrap(); + // Check the returned diff + assert_eq!(diff, (-1, -2, -1, -4)); + let players = DbApi::with_conn(&conn).fetch_players().unwrap(); + let player = players.get(1).unwrap(); + // Check that we can add old value to return diff to get resulting value + assert_eq!( + (player.cp, player.sp, player.gp, player.pp), + (1 + diff.0, 2 + diff.1, 3 + diff.2, 4 + diff.3) + ); + } + #[test] fn test_add_player() { let conn = test_connection();