Skip to content

Commit

Permalink
Add'l team start tests (#531)
Browse files Browse the repository at this point in the history
- Fixed a bug that could prevent players from starting a session if they hadn't made a user name change request
- Added additional test coverage for team session start
  • Loading branch information
sei-bstein authored Nov 15, 2024
1 parent a35bf3d commit 74b604d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Gameboard.Api.Common;
using Gameboard.Api.Features.Teams;
using Gameboard.Api.Structure;
using ServiceStack;

namespace Gameboard.Api.Tests.Integration.Teams;

Expand All @@ -10,7 +12,6 @@ public class TeamControllerStartTeamSessionTests(GameboardTestContext testContex
[Theory, GbIntegrationAutoData]
public async Task TeamGame_WithSinglePlayer_CantStart
(
string gameId,
string playerId,
string userId,
IFixture fixture
Expand All @@ -21,7 +22,7 @@ await _testContext.WithDataState(state =>
{
state.Add(new Data.Game
{
Id = gameId,
Id = fixture.Create<string>(),
MinTeamSize = 2,
MaxTeamSize = 5,
GameStart = DateTimeOffset.UtcNow,
Expand All @@ -46,7 +47,6 @@ await _testContext
[Theory, GbIntegrationAutoData]
public async Task TeamGame_WithTwoPlayers_CanStart
(
string gameId,
string playerId,
string userId,
string teamId,
Expand All @@ -58,7 +58,7 @@ await _testContext.WithDataState(state =>
{
state.Add(new Data.Game
{
Id = gameId,
Id = fixture.Create<string>(),
MinTeamSize = 2,
MaxTeamSize = 5,
GameStart = DateTimeOffset.UtcNow,
Expand Down Expand Up @@ -93,4 +93,70 @@ await _testContext.WithDataState(state =>
// then we should get a player back with a nonempty session start
result.SessionBegin.ShouldBeGreaterThan(DateTimeOffset.MinValue);
}

[Theory, GbIntegrationAutoData]
public async Task TeamGame_WithCaptainPromotion_CanStart
(
string finalCaptainPlayerId,
string finalCaptainUserId,
string initialCaptainPlayerId,
string initialCaptainUserId,
string teamId,
IFixture fixture
)
{
// given a team game and a registered player with no teammates
await _testContext.WithDataState(state =>
{
state.Add(new Data.Game
{
Id = fixture.Create<string>(),
MinTeamSize = 2,
MaxTeamSize = 5,
GameStart = DateTimeOffset.UtcNow,
GameEnd = DateTimeOffset.UtcNow.AddDays(1),
Mode = GameEngineMode.Standard,
Players =
[
state.Build<Data.Player>(fixture, p =>
{
p.Id = initialCaptainPlayerId;
p.Role = PlayerRole.Manager;
p.TeamId = teamId;
p.User = state.Build<Data.User>(fixture, u => u.Id = initialCaptainUserId);
}),
state.Build<Data.Player>(fixture, p =>
{
p.Id = finalCaptainPlayerId;
p.Role = PlayerRole.Member;
p.TeamId = teamId;
p.User = state.Build<Data.User>(fixture, u => u.Id = finalCaptainUserId);
})
]
});
});

// when they promote a new captain and then start
var httpClient = _testContext.CreateHttpClientWithActingUser(u => u.Id = initialCaptainUserId);

await httpClient
.PutAsync($"api/team/{teamId}/manager/{finalCaptainPlayerId}", new PromoteToManagerRequest
{
CurrentManagerPlayerId = initialCaptainPlayerId,
NewManagerPlayerId = finalCaptainPlayerId,
TeamId = teamId
}.ToJsonBody());

var result = await _testContext
.CreateHttpClientWithActingUser(u => u.Id = finalCaptainUserId)
.PutAsync($"api/player/{finalCaptainPlayerId}/start", null)
.DeserializeResponseAs<Player>();

// then we should get a player back with a nonempty session start
result.SessionBegin.ShouldBeGreaterThan(DateTimeOffset.MinValue);
}

// Users can team up, leave the team, join a different team, then start sessions on the original and the new team
// Admins can start sessions for non-admins
// Non-admins can't start sessions for other teams
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ await _permissionsService.Can(PermissionKey.Play_IgnoreExecutionWindow),
);

// start all sessions
// (note that this effective synchronizes all teams starting in this command)
// (note that this effectively synchronizes all teams starting in this command)
_logger.LogInformation($"Starting sessions for {request.TeamIds.Count()} teams...");
await _teamService.SetSessionWindow(request.TeamIds, sessionWindow, cancellationToken);
_logger.LogInformation($"Sessions started.");
Expand Down

0 comments on commit 74b604d

Please sign in to comment.