-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new endpoint for synchronising by candidate ID
- Loading branch information
Showing
6 changed files
with
209 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
|
||
namespace GetIntoTeachingApi.Models | ||
{ | ||
public class CandidateIdsRequest | ||
{ | ||
public int[] CandidateIds { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,33 @@ public async Task RunAsync_WhenMultiplePagesAvailable_QueuesCandidateJobsForEach | |
(DateTime)job.Args[0] == updatedSince && (int)job.Args[1] == (ApplyBackfillJob.PagesPerJob + 1)), | ||
It.IsAny<EnqueuedState>()), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task RunAsync_WithCandidateIds() | ||
{ | ||
int[] candidateIds = new[] { 1,2,3 }; | ||
var candidate1 = new Candidate() { Id = "1", Attributes = new CandidateAttributes() { Email = $"[email protected]" } }; | ||
var candidate2 = new Candidate() { Id = "2", Attributes = new CandidateAttributes() { Email = $"[email protected]" } }; | ||
var candidate3 = new Candidate() { Id = "3", Attributes = new CandidateAttributes() { Email = $"[email protected]" } }; | ||
|
||
using (var httpTest = new HttpTest()) | ||
{ | ||
MockIndividualResponse(httpTest, new Response<Candidate>() { Data = candidate1 }, 1); | ||
MockIndividualResponse(httpTest, new Response<Candidate>() { Data = candidate2 }, 2); | ||
MockIndividualResponse(httpTest, new Response<Candidate>() { Data = candidate3 }, 3); | ||
|
||
await _job.RunAsync(DateTime.MinValue, 1, candidateIds); | ||
} | ||
|
||
_mockJobClient.Verify(x => x.Create( | ||
It.Is<Job>(job => job.Type == typeof(ApplyCandidateSyncJob) && job.Method.Name == "Run"), | ||
It.IsAny<ScheduledState>()), Times.Exactly(3)); | ||
|
||
_mockAppSettings.VerifySet(m => m.IsApplyBackfillInProgress = true, Times.Once); | ||
_mockLogger.VerifyInformationWasCalled("ApplyBackfillJob - Started - Pages 1 to 10"); | ||
_mockLogger.VerifyInformationWasCalled("ApplyBackfillJob - Succeeded - Pages 1 to 10"); | ||
_mockAppSettings.VerifySet(m => m.IsApplyBackfillInProgress = false, Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task RunAsync_WithNoCandidates_DoesNotQueueJobs() | ||
|
@@ -122,5 +149,16 @@ private void MockResponse(HttpTest httpTest, Response<IEnumerable<Candidate>> re | |
.WithHeader("Authorization", $"Bearer {_mockEnv.Object.ApplyCandidateApiKey}") | ||
.RespondWith(json, 200, headers); | ||
} | ||
|
||
private void MockIndividualResponse(HttpTest httpTest, Response<Candidate> response, int candidateId) | ||
{ | ||
var json = JsonConvert.SerializeObject(response); | ||
|
||
httpTest | ||
.ForCallsTo($"{_mockEnv.Object.ApplyCandidateApiUrl}/candidates/C{candidateId}") | ||
.WithVerb("GET") | ||
.WithHeader("Authorization", $"Bearer {_mockEnv.Object.ApplyCandidateApiKey}") | ||
.RespondWith(json, 200); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
GetIntoTeachingApiTests/Models/CandidateIdsRequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FluentAssertions; | ||
using GetIntoTeachingApi.Models; | ||
using Xunit; | ||
|
||
namespace GetIntoTeachingApiTests.Models | ||
{ | ||
public class CandidateIdsRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_WithInitializer() | ||
{ | ||
var candidateIdsRequest = new CandidateIdsRequest { CandidateIds = new[] { 1, 2, 3 } }; | ||
|
||
candidateIdsRequest.CandidateIds.Should().Equal(1, 2, 3); | ||
} | ||
} | ||
} |