Skip to content

Commit

Permalink
Merge pull request #250 from DFE-Digital/remove-fully-booked-quotas
Browse files Browse the repository at this point in the history
Omit callback booking quotas that are full
  • Loading branch information
ethax-ross authored Sep 16, 2020
2 parents 004226d + c2b19e7 commit 641357b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions GetIntoTeachingApi/Services/CrmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public IEnumerable<CallbackBookingQuota> GetCallbackBookingQuotas()
{
return _service.CreateQuery("dfe_callbackbookingquota", Context())
.Where((entity) => entity.GetAttributeValue<DateTime>("dfe_starttime") > DateTime.UtcNow &&
entity.GetAttributeValue<DateTime>("dfe_starttime") <
DateTime.UtcNow.AddDays(MaximumCallbackBookingQuotaDaysInAdvance))
entity.GetAttributeValue<DateTime>("dfe_starttime") < DateTime.UtcNow.AddDays(MaximumCallbackBookingQuotaDaysInAdvance) &&
entity.GetAttributeValue<int>("dfe_websitenumberofbookings") < entity.GetAttributeValue<int>("dfe_websitequota"))
.OrderBy((entity) => entity.GetAttributeValue<DateTime>("dfe_starttime"))
.Select((entity) => new CallbackBookingQuota(entity, this));
}
Expand Down
15 changes: 12 additions & 3 deletions GetIntoTeachingApiTests/Services/CrmServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.Xrm.Sdk.Query;
using Xunit;
using static Microsoft.PowerPlatform.Cds.Client.CdsServiceClient;
using FluentAssertions.Common;
using System.Linq.Dynamic.Core;

namespace GetIntoTeachingApiTests.Services
Expand Down Expand Up @@ -111,7 +110,7 @@ private static bool VerifyTeachingEventsQueryExpression(QueryExpression query)
}

[Fact]
public void GetCallbackBookingQuotas_ReturnsFutureQuotasUpTo14DaysInAdvance()
public void GetCallbackBookingQuotas_ReturnsFutureQuotasUpTo14DaysInAdvanceExcludingFullyBooked()
{
var queryableQuotas = MockCallbackBookingQuotas();
_mockService.Setup(mock => mock.CreateQuery("dfe_callbackbookingquota", _context))
Expand Down Expand Up @@ -471,24 +470,34 @@ private static IQueryable<Entity> MockCallbackBookingQuotas()
var quota1 = new Entity("dfe_callbackbookingquota");
quota1["dfe_starttime"] = DateTime.UtcNow.AddDays(-1);
quota1["dfe_websitenumberofbookings"] = 1;
quota1["dfe_websitequota"] = 10;

var quota2 = new Entity("dfe_callbackbookingquota");
quota2["dfe_starttime"] = DateTime.UtcNow.AddDays(10);
quota2["dfe_websitenumberofbookings"] = 2;
quota2["dfe_websitequota"] = 10;

var quota3 = new Entity("dfe_callbackbookingquota");
quota3["dfe_starttime"] = DateTime.UtcNow.AddDays(1);
quota3["dfe_websitenumberofbookings"] = 3;
quota3["dfe_websitequota"] = 10;

var quota4 = new Entity("dfe_callbackbookingquota");
quota4["dfe_starttime"] = DateTime.UtcNow.AddMinutes(20);
quota4["dfe_websitenumberofbookings"] = 4;
quota4["dfe_websitequota"] = 10;

var quota5 = new Entity("dfe_callbackbookingquota");
quota5["dfe_starttime"] = DateTime.UtcNow.AddDays(15);
quota5["dfe_websitenumberofbookings"] = 5;
quota5["dfe_websitequota"] = 10;

return new[] { quota1, quota2, quota3, quota4, quota5 }.AsQueryable();
var quota6 = new Entity("dfe_callbackbookingquota");
quota5["dfe_starttime"] = DateTime.UtcNow.AddDays(3);
quota5["dfe_websitenumberofbookings"] = 10;
quota5["dfe_websitequota"] = 10;

return new[] { quota1, quota2, quota3, quota4, quota5, quota6 }.AsQueryable();
}

private static IQueryable<Entity> MockPrivacyPolicies()
Expand Down

0 comments on commit 641357b

Please sign in to comment.