Skip to content

Commit

Permalink
More date filtering (#62)
Browse files Browse the repository at this point in the history
* Revert "telemetry logging (#60)" as it was preventing app from running locally

* adding end date filter on gift cards

* fixing start and end date filters on deals
  • Loading branch information
eebbesen authored Jan 3, 2025
1 parent 6d58154 commit 2f676ca
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 51 deletions.
8 changes: 4 additions & 4 deletions StpFoodBlazor/StpFoodBlazor/Helpers/GiftCardFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public GiftCard[] Filter() {
if (GiftCards == null) {
return [];
}
return FilterByExpiryDate(GiftCards);
return FilterByDates(GiftCards);
}

private static DateTime convertStringToDate(string date) {
return DateTime.Parse(date, CultureInfo.InvariantCulture);
}

private GiftCard[] FilterByExpiryDate(GiftCard[] giftcards) {
private GiftCard[] FilterByDates(GiftCard[] giftcards) {
return giftcards.Where(giftcard =>
string.IsNullOrWhiteSpace(giftcard.End) ||
convertStringToDate(giftcard.End).Date > _timeService.GetCurrentDate().Date
(string.IsNullOrWhiteSpace(giftcard.Start) || convertStringToDate(giftcard.Start).Date <= _timeService.GetCurrentDate().Date) &&
(string.IsNullOrWhiteSpace(giftcard.End) || convertStringToDate(giftcard.End).Date >= _timeService.GetCurrentDate().Date)
).ToArray();
}
}
Expand Down
2 changes: 0 additions & 2 deletions StpFoodBlazor/StpFoodBlazor/Models/Deal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public class DealEvent

[JsonPropertyName("Happy Hour")]
public string? HappyHour { get; set; }
[JsonPropertyName("Start Date")]
public string? Start { get; set; }
[JsonPropertyName("End Date")]
public string? End { get; set; }
}
}
3 changes: 0 additions & 3 deletions StpFoodBlazor/StpFoodBlazor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using StpFoodBlazor.Components;
using StpFoodBlazor.Services;
using Azure.Monitor.OpenTelemetry.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
Expand All @@ -9,8 +8,6 @@
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
builder.Services.AddOpenTelemetry().UseAzureMonitor();

builder.Services.AddHttpClient();
builder.Services.AddScoped<IDealService, HttpDealService>();
builder.Services.AddScoped<ITimeService, TimeService>();
Expand Down
1 change: 0 additions & 1 deletion StpFoodBlazor/StpFoodBlazor/StpFoodBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
<ProjectReference Include="..\StpFoodBlazor.Client\StpFoodBlazor.Client.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.10" />
</ItemGroup>
Expand Down
38 changes: 33 additions & 5 deletions StpFoodBlazor/StpFoodBlazorTest/Helpers/GiftCardFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public void Filter_FiltersCorrectly()
GiftCardFixtures.kincaids
};

GiftCardFilter GiftCardFilter = new(timeService);
GiftCardFilter.GiftCards = GiftCardFixtures.allGiftCards;;
GiftCardFilter GiftCardFilter = new(timeService)
{
GiftCards = GiftCardFixtures.allGiftCards
};

var filteredGiftCards = GiftCardFilter.Filter();

Expand All @@ -37,19 +39,45 @@ public void Filter_FiltersCorrectly()
}
}

[Fact]
public void Filter_FiltersNotStarted()
{
var expected = new GiftCard[]{
GiftCardFixtures.wildBills,
GiftCardFixtures.wildBills2,
GiftCardFixtures.kincaids
};

GiftCardFilter GiftCardFilter = new(timeService)
{
GiftCards = GiftCardFixtures.allGiftCards
};

timeService.CurrentDate = new DateTime(2025, 12, 10, 0, 0, 0, DateTimeKind.Utc);

var filteredGiftCards = GiftCardFilter.Filter();

for (int i = 0; i < expected.Length; i++)
{
Assert.Equal(expected[i].Deal, filteredGiftCards[i].Deal);
}
}

[Fact]
public void Filter_FiltersExpired()
public void Filter_FiltersEnded()
{
var expected = new GiftCard[]
{
GiftCardFixtures.byLakeElmoInn
};

GiftCardFilter GiftCardFilter = new(timeService);
GiftCardFilter.GiftCards = new GiftCard[]
GiftCardFilter GiftCardFilter = new(timeService)
{
GiftCards =
[
GiftCardFixtures.urbanWok,
GiftCardFixtures.byLakeElmoInn
]
};

timeService.CurrentDate = new DateTime(2024, 12, 10, 0, 0, 0, DateTimeKind.Utc);
Expand Down
13 changes: 7 additions & 6 deletions StpFoodBlazor/StpFoodBlazorTest/Pages/GiftCardsTest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@
}

[Fact]
public void GiftCardsShouldRenderRecords()
public void GiftCardsShouldRenderRecords20241210()
{
timeService.CurrentDate = new DateTime(2024, 12, 10);
var cut = ctx.Render(@<GiftCards />);
var elements = getElements(cut);

Assert.Equal("1881 by Lake Elmo Inn", elements.Children[0].Children[0].InnerHtml);
Assert.Equal("Buy $100 get $20", elements.Children[0].Children[1].InnerHtml);
Assert.Equal("$20 valid 01/01/2025 - 04/30/2025", elements.Children[0].Children[2].InnerHtml);
Assert.Equal("", elements.Children[0].Children[3].InnerHtml);
Assert.Equal("12/24", elements.Children[0].Children[4].InnerHtml);
Assert.Equal("12/24/2024", elements.Children[0].Children[4].InnerHtml);
}

[Fact]
Expand All @@ -60,9 +61,9 @@
var cut = ctx.Render(@<GiftCards />);
var elements = getElements(cut);

Assert.Equal(31, elements.ChildElementCount);
Assert.Equal(30, elements.ChildElementCount);
Assert.Equal("1881 by Lake Elmo Inn", elements.Children[0].Children[0].InnerHtml);
Assert.Equal("Wild Bill Sports Saloon", elements.Children[30].Children[0].InnerHtml);
Assert.Equal("Wild Bill Sports Saloon", elements.Children[29].Children[0].InnerHtml);
}

[Fact]
Expand All @@ -72,9 +73,9 @@
var cut = ctx.Render(@<GiftCards />);
var elements = getElements(cut);

Assert.Equal(38, elements.ChildElementCount);
Assert.Equal(37, elements.ChildElementCount);
Assert.Equal("1881 by Lake Elmo Inn", elements.Children[0].Children[0].InnerHtml);
Assert.Equal("Wild Bill Sports Saloon", elements.Children[37].Children[0].InnerHtml);
Assert.Equal("Wild Bill Sports Saloon", elements.Children[36].Children[0].InnerHtml);
}

private IElement getElements(IRenderedFragment cut)
Expand Down
60 changes: 30 additions & 30 deletions StpFoodBlazor/StpFoodBlazorTest/fixtures/giftcards.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Deal": "Buy $100 get $10",
"Terms": "$10 valid 01/02/2025 - 12/30/2025",
"Start Date": "",
"End Date": "12/23",
"End Date": "12/23/2024",
"URL": "https://damicogiftcards.com/",
"Purchased": null
},
Expand All @@ -14,8 +14,8 @@
"Name": "The Saint Paul Grill",
"Deal": "Buy $100 get $25",
"Terms": "* $25 valid 01/01/2025 - 10/31/2025\n* Must purchase cards in person, not online",
"Start Date": "11/01",
"End Date": "12/31",
"Start Date": "11/01/2024",
"End Date": "12/31/2024",
"URL": "https://www.stpaulgrill.com/gift-cards/",
"Purchased": null
},
Expand All @@ -25,7 +25,7 @@
"Deal": "Buy $25 get a free 6\"",
"Terms": "",
"Start Date": "",
"End Date": "12/31",
"End Date": "12/31/2024",
"URL": "https://www.subway.com/en-us/subwaycard",
"Purchased": null
},
Expand Down Expand Up @@ -104,8 +104,8 @@
"Name": "Red Rabbit",
"Deal": "Buy $100 get $30",
"Terms": "$30 valid 01/01/2025 - 05/31/2025\n$30 valid at Red Cow and Red Rabbit",
"Start Date": "11/28",
"End Date": "11/29",
"Start Date": "11/28/2024",
"End Date": "11/29/2024",
"URL": "https://redrabbitmn.com/holiday-gift-cards/",
"Purchased": "1"
},
Expand All @@ -124,8 +124,8 @@
"Name": "Qdoba",
"Deal": "Buy $50 get $10 ",
"Terms": "Digital bonus is redeemable 1/1/25 through 2/28/25",
"Start Date": "11/01",
"End Date": "12/31",
"Start Date": "11/01/2024",
"End Date": "12/31/2024",
"URL": "https://www.qdoba.com/gift-cards",
"Purchased": null
},
Expand All @@ -134,8 +134,8 @@
"Name": "Qdoba",
"Deal": "Buy $50 get $15",
"Terms": "Digital bonus is redeemable 1/1/25 through 2/28/25",
"Start Date": "11/29",
"End Date": "12/2",
"Start Date": "11/29/2024",
"End Date": "12/2/2024",
"URL": "https://www.qdoba.com/gift-cards?&utm_medium=email&utm_source=paytronix&utm_campaign=1538_2025_us_email_holiday_gift_card_promotion&utm_content=nov_19",
"Purchased": null
},
Expand Down Expand Up @@ -164,8 +164,8 @@
"Name": "Smash Burger",
"Deal": "Buy $25 get $10",
"Terms": "$10 valid 11/18/2024 - 01/30/2025",
"Start Date": "11/18",
"End Date": "12/31",
"Start Date": "11/18/2024",
"End Date": "12/31/2024",
"URL": "https://smashburger.com/deals?lid=m39ye21fp1dj&utm_source=email&utm_campaign=8058_2024_SB_NA_USA_EMAIL_HOLIDAY_GIFT_CARD&utm_medium=marketing&utm_content=cta",
"Purchased": null
},
Expand All @@ -185,7 +185,7 @@
"Deal": "Buy $50 get $10 ",
"Terms": "$10 valid 01/01/2025 - 03/31/2025 at The Freehouse, The Lowry, Longfellow Grill, Edina Grill, 3 Squares, Highland Grill, Groveland Tap",
"Start Date": "",
"End Date": "12/31",
"End Date": "12/31/2024",
"URL": "https://www.blueplaterestaurantco.com/gift-cards",
"Purchased": null
},
Expand All @@ -195,7 +195,7 @@
"Deal": "Buy $100 get $25 ",
"Terms": "$25 valid 01/01/2025 - 03/31/2025 at The Freehouse, The Lowry, Longfellow Grill, Edina Grill, 3 Squares, Highland Grill, Groveland Tap",
"Start Date": "",
"End Date": "12/31",
"End Date": "12/31/2024",
"URL": "https://www.blueplaterestaurantco.com/gift-cards",
"Purchased": null
},
Expand All @@ -204,8 +204,8 @@
"Name": "Blue Plate Restaurants",
"Deal": "Buy $100 get $35 ",
"Terms": "$35 valid 01/01/2025 - 03/31/2025 at The Freehouse, The Lowry, Longfellow Grill, Edina Grill, 3 Squares, Highland Grill, Groveland Tap",
"Start Date": "11/29",
"End Date": "12/2",
"Start Date": "11/29/2024",
"End Date": "12/2/2024",
"URL": "https://www.blueplaterestaurantco.com/gift-cards",
"Purchased": null
},
Expand All @@ -214,8 +214,8 @@
"Name": "Urban Wok",
"Deal": "Buy $25 get $25",
"Terms": "Must purchase in $25 increments to get deal. Full $50 goes to recipient.",
"Start Date": "11/22",
"End Date": "12/2",
"Start Date": "11/22/2024",
"End Date": "12/2/2024",
"URL": "https://www.urbanwokusa.com/",
"Purchased": "4"
},
Expand All @@ -225,7 +225,7 @@
"Deal": "Buy $40 get $10",
"Terms": "$10 valid until 02/28/2025",
"Start Date": "",
"End Date": "12/29",
"End Date": "12/29/2024",
"URL": "https://www.culvers.com/gift-cards",
"Purchased": null
},
Expand All @@ -234,8 +234,8 @@
"Name": "Fandango",
"Deal": "20% off $50 or more with code NOVFLASH24",
"Terms": "",
"Start Date": "11/26",
"End Date": "12/02",
"Start Date": "11/26/2024",
"End Date": "12/02/2024",
"URL": "https://www.fandango.com/fandango-gift-cards",
"Purchased": "1"
},
Expand All @@ -244,8 +244,8 @@
"Name": "Red Lobster",
"Deal": "$90 for $100 gift card and $40 in $10 bonus cards",
"Terms": "Bonus cards valid 1/1/25 through 2/28/25, excluding 2/14/25, and require a minimum purchase of $40",
"Start Date": "11/29",
"End Date": "12/02",
"Start Date": "11/29/2024",
"End Date": "12/02/2024",
"URL": "https://www.redlobster.com/gift-cards/",
"Purchased": null
},
Expand All @@ -265,7 +265,7 @@
"Deal": "$5 off $25",
"Terms": "",
"Start Date": "",
"End Date": "12/02",
"End Date": "12/02/2024",
"URL": "https://potbelly.myguestaccount.com/en-us/guest/egift?page=cardInfo",
"Purchased": "4"
},
Expand All @@ -275,7 +275,7 @@
"Deal": "15% off gift cards with code NAFNAF15",
"Terms": "",
"Start Date": "",
"End Date": "12/02",
"End Date": "12/02/2024",
"URL": "https://wwws-usa1.givex.com/cws4.0/nafnafgrill/",
"Purchased": null
},
Expand All @@ -285,7 +285,7 @@
"Deal": "Buy $100 get $20",
"Terms": "$20 valid 01/01/2025 - 04/30/2025",
"Start Date": "",
"End Date": "12/24",
"End Date": "12/24/2024",
"URL": "https://1881bylei.com/gift-cards/",
"Purchased": null
},
Expand All @@ -304,8 +304,8 @@
"Name": "Chipotle",
"Deal": "Buy $50 get $10 ",
"Terms": "$10 expires 01/31/2025",
"Start Date": "12/18",
"End Date": "12/21",
"Start Date": "12/18/2024",
"End Date": "12/21/2024",
"URL": "https://www.chipotle.com/holiday-gift-cards",
"Purchased": null
},
Expand Down Expand Up @@ -344,8 +344,8 @@
"Name": "Pajarito",
"Deal": "Buy $100 get $30",
"Terms": "",
"Start Date": "11/29",
"End Date": "11/29",
"Start Date": "11/29/2024",
"End Date": "11/29/2024",
"URL": "https://www.instagram.com/p/DC8E1anq0_V/",
"Purchased": "1"
},
Expand Down

0 comments on commit 2f676ca

Please sign in to comment.