Skip to content

Commit

Permalink
test: ✅ Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Oct 4, 2021
1 parent 5fee6d4 commit c35ac16
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
18 changes: 9 additions & 9 deletions src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit()
MovieRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = DateTime.Now.AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_MultipleRequests()
MovieRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_NoRequestsToday()
MovieRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -253,7 +253,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_OneRequestsToday()
Id = "id1"
};

var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -286,7 +286,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_AllRequestsToday()
MovieRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -325,7 +325,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Weekly_NoRequests()
MovieRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var lastWeek = new DateTime(2020, 10, 05).FirstDateInWeek().AddDays(-1); // Day before reset
var lastWeek = new DateTime(2020, 09, 05).FirstDateInWeek().AddDays(-1); // Day before reset
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -428,7 +428,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_NoRequests()
MovieRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1);
var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -460,7 +460,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_OneRequests()
MovieRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
var log = new List<RequestLog>
{
Expand Down Expand Up @@ -494,7 +494,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_AllRequests()
MovieRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
var log = new List<RequestLog>
{
Expand Down
24 changes: 12 additions & 12 deletions src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit()
MusicRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = DateTime.UtcNow.AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_MultipleRequests()
MusicRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_NoRequestsToday()
MusicRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -253,7 +253,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_OneRequestsToday()
Id = "id1"
};

var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -286,7 +286,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_AllRequestsToday()
MusicRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -325,7 +325,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_NoRequests()
MusicRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var lastWeek = new DateTime(2020, 10, 05).FirstDateInWeek().AddDays(-1); // Day before reset
var lastWeek = new DateTime(2020, 09, 05).FirstDateInWeek().AddDays(-1); // Day before reset
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -390,20 +390,20 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_AllRequestsWeek()
MusicRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
{
UserId = "id1",
RequestType = RequestType.Album,
RequestDate = today,
RequestDate = today.AddMinutes(-2),
},
new RequestLog
{
UserId = "id1",
RequestType = RequestType.Album,
RequestDate = today,
RequestDate = today.AddMinutes(-1),
},
};
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
Expand All @@ -428,7 +428,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_NoRequests()
MusicRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1);
var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -460,7 +460,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_OneRequests()
MusicRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
var log = new List<RequestLog>
{
Expand Down Expand Up @@ -494,7 +494,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_AllRequests()
MusicRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
var log = new List<RequestLog>
{
Expand Down
26 changes: 13 additions & 13 deletions src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit()
EpisodeRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = DateTime.UtcNow.AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_MultipleRequests()
EpisodeRequestLimit = 2,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -225,7 +225,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_NoRequestsToday()
EpisodeRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var yesterday = new DateTime(2020, 10, 05).AddDays(-1);
var yesterday = new DateTime(2020, 09, 05).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -258,7 +258,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_OneRequestsToday()
EpisodeRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -292,7 +292,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_AllRequestsToday()
EpisodeRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -333,7 +333,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_MultipleEpisodeRequests()
EpisodeRequestLimitType = RequestLimitType.Day,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -407,7 +407,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_OneRequestsWeek()
EpisodeRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -441,7 +441,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_AllRequestsWeek()
EpisodeRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -482,7 +482,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_MultipleEpisodeRequests(
EpisodeRequestLimitType = RequestLimitType.Week,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -523,7 +523,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_NoRequests()
EpisodeRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1);
var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1);
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -556,7 +556,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_OneRequests()
EpisodeRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -590,7 +590,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_AllRequests()
EpisodeRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down Expand Up @@ -631,7 +631,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_MultipleEpisodeReuests(
EpisodeRequestLimitType = RequestLimitType.Month,
Id = "id1"
};
var today = new DateTime(2020, 10, 05);
var today = DateTime.UtcNow;
var log = new List<RequestLog>
{
new RequestLog
Expand Down
4 changes: 2 additions & 2 deletions src/Ombi.Core/Services/RequestLimitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static async Task<RequestQuotaCountModel> CalculateBasicRemaingRequests(
nextRequest = oldestRequestedAt.AddDays(1).Date;
break;
case RequestLimitType.Week:
var fdow = DateTime.UtcNow.FirstDateInWeek();
var fdow = DateTime.UtcNow.FirstDateInWeek().Date;
count = limit - await log.CountAsync(x => x.RequestDate >= fdow);
oldestRequestedAt = await log.Where(x => x.RequestDate >= fdow)
.OrderBy(x => x.RequestDate)
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task<RequestQuotaCountModel> GetRemainingTvRequests(OmbiUser user)
nextRequest = oldestRequestedAt.AddDays(1).Date;
break;
case RequestLimitType.Week:
var fdow = now.FirstDateInWeek();
var fdow = now.FirstDateInWeek().Date;
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7));
// Needed, due to a bug which would cause all episode counts to be 0
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
Expand Down

0 comments on commit c35ac16

Please sign in to comment.