From d6de6254a4e3833c6333700e19aa6bd2d46d8ab9 Mon Sep 17 00:00:00 2001 From: Vivian Date: Thu, 10 Jun 2021 13:56:36 +0100 Subject: [PATCH] Added integration tests for API error show error summary --- .../IntegrationTestingWebApplicationFactory.cs | 10 ++++++++++ .../Pages/BaseIntegrationTests.MockData.cs | 5 +++++ .../RationaleForProjectIntegrationTests.cs | 13 +++++++++++++ .../Rationale/RationaleForTrustIntegrationTests.cs | 13 +++++++++++++ 4 files changed, 41 insertions(+) diff --git a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/IntegrationTestingWebApplicationFactory.cs b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/IntegrationTestingWebApplicationFactory.cs index 38e6967ec..312553a48 100644 --- a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/IntegrationTestingWebApplicationFactory.cs +++ b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/IntegrationTestingWebApplicationFactory.cs @@ -69,6 +69,16 @@ public void AddPatchWithJsonRequest(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) diff --git a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/BaseIntegrationTests.MockData.cs b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/BaseIntegrationTests.MockData.cs index 5687db926..9af0cd02e 100644 --- a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/BaseIntegrationTests.MockData.cs +++ b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/BaseIntegrationTests.MockData.cs @@ -42,6 +42,11 @@ public Project AddGetProject(Action 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()); diff --git a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForProjectIntegrationTests.cs b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForProjectIntegrationTests.cs index 94a3262fd..df450a048 100644 --- a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForProjectIntegrationTests.cs +++ b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForProjectIntegrationTests.cs @@ -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("form").SubmitAsync(); + + Document.QuerySelector(".govuk-error-summary").Should().NotBeNull(); + } } } diff --git a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForTrustIntegrationTests.cs b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForTrustIntegrationTests.cs index e3856c105..423e30032 100644 --- a/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForTrustIntegrationTests.cs +++ b/ApplyToBecomeInternal/ApplyToBecomeInternal.Tests/Pages/Rationale/RationaleForTrustIntegrationTests.cs @@ -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("form").SubmitAsync(); + + Document.QuerySelector(".govuk-error-summary").Should().NotBeNull(); + } + [Fact] public async Task Should_navigate_back_to_rationale_from_rationale_for_trust() {