From fcb265c4903f669578f877d537211a0a66061e71 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 28 Jun 2019 16:29:19 +0200 Subject: [PATCH] More tests! --- draftbot/draftbot_test.go | 69 ++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/draftbot/draftbot_test.go b/draftbot/draftbot_test.go index 500f900..c8dd6a6 100644 --- a/draftbot/draftbot_test.go +++ b/draftbot/draftbot_test.go @@ -118,7 +118,7 @@ func TestDraftSessionButEverythingGoesWrong(t *testing.T) { // Try creating a new session as NOT the owner mock.message("test-guest", "create", draft.SessionOptions{ - Players: 8, // Two players, six bots + Players: 8, Options: draft.DraftOptions{ Type: draft.DraftSet, Positioning: draft.PosEven, @@ -128,12 +128,66 @@ func TestDraftSessionButEverythingGoesWrong(t *testing.T) { }) mock.expect(t, "must-be-owner", 5) - //TODO: - // Try to start session when session doesn't exist - // Try to create session twice - // Try to start session with no players - // Try to start session as not the owner - // Try to make too many players join a session + // Try creating a session with an invalid type + mock.message("test-owner", "create", draft.SessionOptions{ + Players: 8, + Options: draft.DraftOptions{ + Type: "lolwhat", + }, + }) + mock.expect(t, "session-create-error", 5) + + // Try creating a session with invalid data + mock.message("test-owner", "create", 42) + mock.expect(t, "invalid-data", 5) + + // Try starting a session that doesn't exist + mock.message("test-owner", "start", nil) + mock.expect(t, "command-unavailable", 5) + + // Try creating the session twice + mock.message("test-owner", "create", draft.SessionOptions{ + Players: 2, + Options: draft.DraftOptions{ + Type: draft.DraftSet, + Positioning: draft.PosEven, + Set: mlp.SetAbsoluteDiscord, + PackCount: 4, + }, + }) + mock.expect(t, "session-open", 5) + + mock.message("test-owner", "create", draft.SessionOptions{ + Players: 2, + Options: draft.DraftOptions{ + Type: draft.DraftSet, + Positioning: draft.PosEven, + Set: mlp.SetAbsoluteDiscord, + PackCount: 4, + }, + }) + mock.expect(t, "command-unavailable", 5) + + // Try to start session when no-one has joined + mock.message("test-owner", "start", nil) + mock.expect(t, "session-start-error", 5) + + // Try to make too many players join + mock.message("a", "join", nil) + mock.expect(t, "player-joined-session", 5) + mock.message("b", "join", nil) + mock.expect(t, "player-joined-session", 5) + mock.message("c", "join", nil) + mock.expect(t, "session-full", 5) + + // Try to make someone join a session that already started + mock.message("test-owner", "start", nil) + mock.multiexpect(t, 5, "session-start", "draft-order") + + mock.message("c", "join", nil) + mock.expect(t, "session-already-started", 5) + + //TODO More picking, etc shenanigans } func (m *MockServer) expect(t *testing.T, typ string, timeout int) { @@ -183,7 +237,6 @@ func (m *MockServer) multiexpect(t *testing.T, timeout int, types ...string) { // Oh noes t.Fatalf("Expected one of %s but got \"%s\"", types, msg.Message.Type) } - return case <-time.After(time.Duration(timeout) * time.Second): t.Fatalf("Expected one of %s but found nothing (timeout after %d seconds)!", types, timeout) }