From c29c1e64803dc5dfd33db78503b8f977bc603e3a Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 19 Apr 2026 22:17:12 +0200 Subject: [PATCH] feat: update draw offer test to include draw decline scenario --- .../engine/GameEngineDrawOfferTest.scala | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/scala/de/nowchess/chess/engine/GameEngineDrawOfferTest.scala b/modules/core/src/test/scala/de/nowchess/chess/engine/GameEngineDrawOfferTest.scala index 177d7a2..2eef599 100644 --- a/modules/core/src/test/scala/de/nowchess/chess/engine/GameEngineDrawOfferTest.scala +++ b/modules/core/src/test/scala/de/nowchess/chess/engine/GameEngineDrawOfferTest.scala @@ -194,7 +194,7 @@ class GameEngineDrawOfferTest extends AnyFunSuite with Matchers: case other => fail(s"Expected InvalidMoveEvent, but got $other") - test("Draw offer is cleared when game ends by resignation"): + test("Draw offer is cleared when game ends by resignation (accept)"): val engine = new GameEngine() val observer = new DrawOfferMockObserver() engine.subscribe(observer) @@ -214,6 +214,26 @@ class GameEngineDrawOfferTest extends AnyFunSuite with Matchers: case other => fail(s"Expected InvalidMoveEvent, but got $other") + test("Draw offer is cleared when game ends by resignation"): + val engine = new GameEngine() + val observer = new DrawOfferMockObserver() + engine.subscribe(observer) + + engine.offerDraw(Color.White) + observer.events.clear() + engine.resign(Color.Black) + + // Try to accept the now-cleared draw offer + observer.events.clear() + engine.declineDraw(Color.White) + + observer.events should have length 1 + observer.events.head match + case event: InvalidMoveEvent => + event.reason shouldBe InvalidMoveReason.GameAlreadyOver + case other => + fail(s"Expected InvalidMoveEvent, but got $other") + private class DrawOfferMockObserver extends Observer: val events = mutable.ListBuffer[GameEvent]()