Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Include the winning team as a badge (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsampica authored Jul 2, 2022
1 parent d3a8e53 commit 84e5c9e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/Client/Features/FreeAgents/List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@
</MudTd>
<MudTd DataLabel="Player Position">@context.Position</MudTd>
<MudTd DataLabel="Player Team">@context.Team</MudTd>
<MudTd DataLabel="Bidding Ends">@context.BiddingEnds.ToShortDateString()</MudTd>
<MudTd DataLabel="Bidding Ends">
@context.BiddingEnds.ToShortDateString()
</MudTd>
<MudTd DataLabel="Highest Bid">
<div>
@context.HighestBid
<span>
@context.HighestBid.ToString("C")
@if (context.CurrentUserIsHighestBidder)
{
<MudChip Color=Color.Success Icon=@Icons.Outlined.Check Size=Size.Small>You!</MudChip>
<MudChip Color=Color.Success Size=Size.Small>You!</MudChip>
}
else if(context.WinningTeam != null)
{
<MudChip Color=Color.Error Size=Size.Small>@context.WinningTeam</MudChip>
}
</div>
</span>
</MudTd>
</RowTemplate>
<PagerContent>
Expand Down
4 changes: 3 additions & 1 deletion src/Server/Features/FreeAgents/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public async Task<FreeAgentListResult> Handle(ListQuery request, CancellationTok
var freeAgents = await _dbContext.Players
.Include(p => p.Team)
.Include(p => p.Bids)
.ThenInclude(b => b.Team)
.WhereIsFreeAgent()
.OrderBy(p => p.EndOfFreeAgency)
.ProjectTo<FreeAgentListResult.FreeAgentItem>(_mapper.ConfigurationProvider, new { currentUserTeamId })
Expand All @@ -78,6 +79,7 @@ public ListMappingProfile()
s.Bids.FindHighestBid()!.TeamId == currentUserTeamId)
)
.ForMember(d => d.BiddingEnds, mo => mo.MapFrom(s => s.EndOfFreeAgency!.Value))
.ForMember(d => d.HighestBid, mo => mo.MapFrom(s => s.GetHighestBidAmount()));
.ForMember(d => d.HighestBid, mo => mo.MapFrom(s => s.GetHighestBidAmount()))
.ForMember(d => d.WinningTeam, mo => mo.MapFrom(s => s.Bids.Any() ? s.Bids.FindHighestBid()!.Team.Name : null));
}
}
1 change: 1 addition & 0 deletions src/Shared/Features/FreeAgents/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class FreeAgentItem
public DateTime BiddingEnds { get; set; }
public int HighestBid { get; set; }
public bool CurrentUserIsHighestBidder { get; set; }
public string? WinningTeam { get; set; }
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/Tests/Features/FreeAgents/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,34 @@ public async Task GivenAnyAuthenticatedUser_WhenThereIsOnePlayerWhoIsAFreeAgent_
freeAgent.BiddingEnds.Should().Be(biddingEnds);
freeAgent.CurrentUserIsHighestBidder.Should().BeTrue();
}

[Fact]
public async Task GivenAnyAuthenticatedUser_WhenAFreeAgentHasABidByAnotherTeam_ThenThatTeamShowsAsTheWinningTeam()
{
var application = CreateUserAuthenticatedApplication();

var mockTeam = CreateFakeTeam();
await application.AddAsync(mockTeam);

var mockPlayer = CreateFakePlayer();
mockPlayer.TeamId = mockTeam.Id;
mockPlayer.SetToRostered(DateTime.MinValue.Year, int.MaxValue);
var biddingEnds = DateTime.MaxValue;
mockPlayer.SetToFreeAgent(biddingEnds);
await application.AddAsync(mockPlayer);

var winningTeam = CreateFakeTeam();
await application.AddAsync(winningTeam);

var bidAmount = int.MaxValue;
mockPlayer.AddBid(bidAmount, winningTeam.Id);
await application.UpdateAsync(mockPlayer);

var client = application.CreateClient();

var result = await client.GetFromJsonAsync<FreeAgentListResult>(FreeAgentListRouteFactory.Uri);

var freeAgent = result!.FreeAgents.First();
freeAgent.WinningTeam.Should().Be(winningTeam.Name);
}
}

0 comments on commit 84e5c9e

Please sign in to comment.