Skip to content

Commit

Permalink
Added BuyWindows to Session models as computed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonbrett committed Jan 2, 2025
1 parent 3845ffe commit 3b82c1a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
78 changes: 78 additions & 0 deletions HockeyPickup.Api.Tests/ModelTests/SessionResponseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using HockeyPickup.Api.Models.Responses;

namespace HockeyPickup.Api.Tests.ModelTests;

public class SessionDetailedResponseTests
{
[Fact]
public void BuyWindow_ShouldReturnCorrectDateTime()
{
// Arrange
var sessionDate = new DateTime(2025, 2, 25, 7, 30, 0);
var buyDayMinimum = 6;
var expectedBuyWindow = new DateTime(2025, 2, 19, 9, 30, 0);

var session = new SessionDetailedResponse
{
SessionId = 1,
CreateDateTime = DateTime.Now,
UpdateDateTime = DateTime.Now,
SessionDate = sessionDate,
BuyDayMinimum = buyDayMinimum
};

// Act
var actualBuyWindow = session.BuyWindow;

// Assert
Assert.Equal(expectedBuyWindow, actualBuyWindow);
}

[Fact]
public void BuyWindowPreferred_ShouldReturnCorrectDateTime()
{
// Arrange
var sessionDate = new DateTime(2025, 2, 25, 7, 30, 0);
var buyDayMinimum = 6;
var expectedBuyWindowPreferred = new DateTime(2025, 2, 18, 9, 30, 0);

var session = new SessionDetailedResponse
{
SessionId = 1,
CreateDateTime = DateTime.Now,
UpdateDateTime = DateTime.Now,
SessionDate = sessionDate,
BuyDayMinimum = buyDayMinimum
};

// Act
var actualBuyWindowPreferred = session.BuyWindowPreferred;

// Assert
Assert.Equal(expectedBuyWindowPreferred, actualBuyWindowPreferred);
}

[Fact]
public void BuyWindowPreferredPlus_ShouldReturnCorrectDateTime()
{
// Arrange
var sessionDate = new DateTime(2025, 2, 25, 7, 30, 0);
var buyDayMinimum = 6;
var expectedBuyWindowPreferredPlus = new DateTime(2025, 2, 18, 9, 25, 0);

var session = new SessionDetailedResponse
{
SessionId = 1,
CreateDateTime = DateTime.Now,
UpdateDateTime = DateTime.Now,
SessionDate = sessionDate,
BuyDayMinimum = buyDayMinimum
};

// Act
var actualBuyWindowPreferredPlus = session.BuyWindowPreferredPlus;

// Assert
Assert.Equal(expectedBuyWindowPreferredPlus, actualBuyWindowPreferredPlus);
}
}
24 changes: 24 additions & 0 deletions HockeyPickup.Api/Models/Responses/SessionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ public class SessionBasicResponse
[GraphQLName("SessionDetailed")]
public class SessionDetailedResponse : SessionBasicResponse
{
[Description("Buy window for the session")]
[DataType(DataType.DateTime)]
[JsonPropertyName("BuyWindow")]
[JsonProperty(nameof(BuyWindow))]
[GraphQLName("BuyWindow")]
[GraphQLDescription("Buy window for the session")]
public DateTime BuyWindow => SessionDate.AddDays(-BuyDayMinimum.GetValueOrDefault()).AddHours(2);

[Description("Buy window for preferred users")]
[DataType(DataType.DateTime)]
[JsonPropertyName("BuyWindowPreferred")]
[JsonProperty(nameof(BuyWindowPreferred))]
[GraphQLName("BuyWindowPreferred")]
[GraphQLDescription("Buy window for preferred users")]
public DateTime BuyWindowPreferred => SessionDate.AddDays(-BuyDayMinimum.GetValueOrDefault() - 1).AddHours(2);

[Description("Buy window for preferred plus users")]
[DataType(DataType.DateTime)]
[JsonPropertyName("BuyWindowPreferredPlus")]
[JsonProperty(nameof(BuyWindowPreferredPlus))]
[GraphQLName("BuyWindowPreferredPlus")]
[GraphQLDescription("Buy window for preferred plus users")]
public DateTime BuyWindowPreferredPlus => SessionDate.AddDays(-BuyDayMinimum.GetValueOrDefault() - 1).AddHours(2).AddMinutes(-5);

[Description("Buy/sell transactions associated with the session")]
[JsonPropertyName("BuySells")]
[JsonProperty(nameof(BuySells))]
Expand Down

0 comments on commit 3b82c1a

Please sign in to comment.