Skip to content

Commit

Permalink
Merge pull request #261 from DFE-Digital/disable-etag-cache-on-teachi…
Browse files Browse the repository at this point in the history
…ng-events

Disable caching on event search results
  • Loading branch information
ethax-ross authored Sep 28, 2020
2 parents 5197091 + 986bbee commit 11fbefa
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion GetIntoTeachingApi/Attributes/CrmETagAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private string CrmSyncNextExecutionAt()
var recurringJob = connection.GetAllEntriesFromHash(
$"recurring-job:{JobConfiguration.CrmSyncJobId}");

return recurringJob?["NextExecution"];
return recurringJob?["LastExecution"];
}
}
}
1 change: 0 additions & 1 deletion GetIntoTeachingApi/Controllers/TeachingEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public TeachingEventsController(
}

[HttpGet]
[CrmETag]
[Route("search")]
[SwaggerOperation(
Summary = "Searches for teaching events.",
Expand Down
6 changes: 3 additions & 3 deletions GetIntoTeachingApiTests/Attributes/CrmETagAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void OnActionExecuting_BeforeFirstCrmSyncJobHasRan_RespondsWithAnETag()
public void OnActionExecuting_AfterCrmSyncJobHasRan_RespondsWithNewETag()
{
const string eTag = "03AC2E21CC0F0298899728A7648684A16B08DF1EA22AAD296AC916B50D6A9FE1";
var jobDetails = new Dictionary<string, string>() { { "NextExecution", "2020-01-01 19:52:44" } };
var jobDetails = new Dictionary<string, string>() { { "LastExecution", "2020-01-01 19:52:44" } };
_mockStorageConnection.Setup(m => m.GetAllEntriesFromHash(
$"recurring-job:{JobConfiguration.CrmSyncJobId}")).Returns(jobDetails);
_mockHttpContext.Setup(m => m.Request.Headers["If-None-Match"]).Returns<string>(null);
Expand All @@ -141,7 +141,7 @@ public void OnActionExecuting_AfterCrmSyncJobHasRan_RespondsWithNewETag()
public void OnActionExecuting_WithMatchingIfNoneMatch_Responds304NotModified()
{
const string eTag = "03AC2E21CC0F0298899728A7648684A16B08DF1EA22AAD296AC916B50D6A9FE1";
var jobDetails = new Dictionary<string, string>() { { "NextExecution", "2020-01-01 19:52:44" } };
var jobDetails = new Dictionary<string, string>() { { "LastExecution", "2020-01-01 19:52:44" } };
_mockStorageConnection.Setup(m => m.GetAllEntriesFromHash(
$"recurring-job:{JobConfiguration.CrmSyncJobId}")).Returns(jobDetails);
_mockHttpContext.Setup(m => m.Request.Headers["If-None-Match"]).Returns(eTag);
Expand All @@ -161,7 +161,7 @@ public void OnActionExecuting_WithMatchingIfNoneMatch_Responds304NotModified()
public void OnActionExecuting_WithDifferentIfNoneMatch_RespondsWithResultAndETag()
{
const string eTag = "03AC2E21CC0F0298899728A7648684A16B08DF1EA22AAD296AC916B50D6A9FE1";
var jobDetails = new Dictionary<string, string>() { { "NextExecution", "2020-01-01 19:52:44" } };
var jobDetails = new Dictionary<string, string>() { { "LastExecution", "2020-01-01 19:52:44" } };
_mockStorageConnection.Setup(m => m.GetAllEntriesFromHash(
$"recurring-job:{JobConfiguration.CrmSyncJobId}")).Returns(jobDetails);
_mockHttpContext.Setup(m => m.Request.Headers["If-None-Match"]).Returns("wrong-etag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Authorize_IsPresent()
public void CrmETag_IsPresent()
{
JobStorage.Current = new Mock<JobStorage>().Object;
var methods = new [] { "Get", "Search" };
var methods = new [] { "Get" };

methods.ForEach(m => typeof(TeachingEventsController).GetMethod(m).Should().BeDecoratedWith<CrmETagAttribute>());
}
Expand Down

0 comments on commit 11fbefa

Please sign in to comment.