Skip to content

Commit

Permalink
Added integration tests for API error show error summary
Browse files Browse the repository at this point in the history
  • Loading branch information
madeviv committed Jun 10, 2021
1 parent 50417b3 commit d6de625
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public void AddPatchWithJsonRequest<TRequestBody, TResponseBody>(string path, TR
.WithBody(JsonSerializer.Serialize(responseBody)));
}

public void AddErrorResponse(string path, string method)
{
_server
.Given(Request.Create()
.WithPath(path)
.UsingMethod(method))
.RespondWith(Response.Create()
.WithStatusCode(500));
}

private static int AllocateNext()
{
lock (_sync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public Project AddGetProject(Action<Project> postSetup = null)
return (project, request);
}

public void AddPatchError(int id)
{
_factory.AddErrorResponse($"/conversion-projects/{id}", "patch");
}

public SchoolPerformanceModel AddGetSchoolPerformance(string urn)
{
_fixture.Customizations.Add(new OfstedRatingSpecimenBuilder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,18 @@ public async Task Should_update_rationale_for_project()

Document.Url.Should().BeUrl($"/task-list/{project.Id}/rationale");
}

[Fact]
public async Task Should_show_error_summary_when_there_is_an_API_error()
{
var project = AddGetProject();
AddPatchError(project.Id);

await OpenUrlAsync($"/task-list/{project.Id}/confirm-project-trust-rationale/project-rationale");

await Document.QuerySelector<IHtmlFormElement>("form").SubmitAsync();

Document.QuerySelector(".govuk-error-summary").Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public async Task Should_navigate_to_and_update_rationale_for_trust()
Document.Url.Should().BeUrl($"/task-list/{project.Id}/rationale");
}

[Fact]
public async Task Should_show_error_summary_when_there_is_an_API_error()
{
var project = AddGetProject();
AddPatchError(project.Id);

await OpenUrlAsync($"/task-list/{project.Id}/confirm-project-trust-rationale/trust-rationale");

await Document.QuerySelector<IHtmlFormElement>("form").SubmitAsync();

Document.QuerySelector(".govuk-error-summary").Should().NotBeNull();
}

[Fact]
public async Task Should_navigate_back_to_rationale_from_rationale_for_trust()
{
Expand Down

0 comments on commit d6de625

Please sign in to comment.