Skip to content

Commit

Permalink
Merge pull request #167 from bcgov/stories/ecer-989
Browse files Browse the repository at this point in the history
ecer-989 adding additional validation to the repository level for submit + cancel applications
  • Loading branch information
SoLetsDev authored Mar 26, 2024
2 parents 249e992 + ecd6b72 commit 7f2d9b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<string> SaveDraft(Application application, CancellationToken c
public async Task<string> Submit(string applicationId, CancellationToken cancellationToken)
{
await Task.CompletedTask;
var application = context.ecer_ApplicationSet.FirstOrDefault(d => d.ecer_ApplicationId == Guid.Parse(applicationId));
var application = context.ecer_ApplicationSet.FirstOrDefault(d => d.ecer_ApplicationId == Guid.Parse(applicationId) && d.StatusCode == ecer_Application_StatusCode.Draft);
if (application == null) throw new InvalidOperationException($"Application '{applicationId}' not found");

application.StatusCode = ecer_Application_StatusCode.Submitted;
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task<string> Cancel(string applicationId, CancellationToken cancell
{
await Task.CompletedTask;
var application = context.ecer_ApplicationSet.FirstOrDefault(
d => d.ecer_ApplicationId == Guid.Parse(applicationId)
d => d.ecer_ApplicationId == Guid.Parse(applicationId) && d.StatusCode == ecer_Application_StatusCode.Draft
);
if (application == null) throw new InvalidOperationException($"Application '{applicationId}' not found");
application.StatusCode = ecer_Application_StatusCode.Cancelled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,18 @@ public async Task SubmitApplication_QueryShouldReturnStatusSubmitted()
}

[Fact]
public async Task CancelApplication_QueryShouldnotReturnResults()
public async Task SubmitApplicationNotInDraft_ShouldThrowInvalidOperationException()
{
var applicantId = Fixture.AuthenticatedBcscUserId;
var application = new Application(null, applicantId, new[] { CertificationType.OneYear }) { };
application.Status = ApplicationStatus.Submitted;
var savedApplicationId = await repository.SaveDraft(application, CancellationToken.None);

await Assert.ThrowsAsync<InvalidOperationException>(async () => await repository.Submit(savedApplicationId, CancellationToken.None));
}

[Fact]
public async Task CancelApplication_QueryShouldnotReturnResults_ThenTryToCancelAgain_ShouldThrowInvalidOperationException()
{
var applicantId = Fixture.AuthenticatedBcscUserId2;
var application = new Application(null, applicantId, new[] { CertificationType.OneYear });
Expand All @@ -358,6 +369,8 @@ public async Task CancelApplication_QueryShouldnotReturnResults()
await repository.Cancel(savedApplicationId, CancellationToken.None);

(await repository.Query(new ApplicationQuery { ById = savedApplicationId })).ShouldBeEmpty();

await Assert.ThrowsAsync<InvalidOperationException>(async () => await repository.Cancel(savedApplicationId, CancellationToken.None));
}

private CharacterReference CreateCharacterReference()
Expand Down

0 comments on commit 7f2d9b8

Please sign in to comment.