Skip to content

Commit 3fb4bcd

Browse files
committed
feat: Added and applied [ValidateLaCode] to actions and controllers that consume code
1 parent 48fb8bb commit 3fb4bcd

23 files changed

+140
-22
lines changed

web/src/Web.App/Attributes/ValidateArgumentAttribute.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public static partial class ValidateArgumentAttributeRegex
3434

3535
[GeneratedRegex(@"^\d{8}$")]
3636
public static partial Regex CompanyNumberRegex();
37+
38+
[GeneratedRegex(@"^\d{3}$")]
39+
public static partial Regex LaCodeRegex();
3740
}
3841

3942
public class ValidateUrnAttribute() : ValidateArgumentAttribute("urn", ValidateArgumentAttributeRegex.UrnRegex());
4043
public class ValidateCompanyNumberAttribute() : ValidateArgumentAttribute("companyNumber", ValidateArgumentAttributeRegex.CompanyNumberRegex());
44+
public class ValidateLaCodeAttribute() : ValidateArgumentAttribute("code", ValidateArgumentAttributeRegex.LaCodeRegex());

web/src/Web.App/Controllers/Api/EducationHealthCarePlansProxyController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
3+
using Web.App.Attributes;
34
using Web.App.Controllers.Api.Mappers;
45
using Web.App.Controllers.Api.Responses;
56
using Web.App.Domain.NonFinancial;
@@ -23,6 +24,7 @@ public class EducationHealthCarePlansProxyController(
2324
[ProducesResponseType<EducationHealthCarePlansComparisonResponse[]>(StatusCodes.Status200OK)]
2425
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
2526
[Route("comparison")]
27+
[ValidateLaCode]
2628
public async Task<IActionResult> Comparison([FromQuery] string code, [FromQuery] string[]? set = null, CancellationToken cancellationToken = default)
2729
{
2830
try
@@ -53,6 +55,7 @@ public async Task<IActionResult> Comparison([FromQuery] string code, [FromQuery]
5355
[ProducesResponseType<EducationHealthCarePlansHistoryResponse[]>(StatusCodes.Status200OK)]
5456
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
5557
[Route("history")]
58+
[ValidateLaCode]
5659
public async Task<IActionResult> History([FromQuery] string code, CancellationToken cancellationToken = default)
5760
{
5861
try

web/src/Web.App/Controllers/Api/HighNeedsProxyController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
3+
using Web.App.Attributes;
34
using Web.App.Controllers.Api.Mappers;
45
using Web.App.Controllers.Api.Responses;
56
using Web.App.Domain.LocalAuthorities;
@@ -23,6 +24,7 @@ public class HighNeedsProxyController(
2324
[ProducesResponseType<LocalAuthorityHighNeedsComparisonResponse[]>(StatusCodes.Status200OK)]
2425
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
2526
[Route("comparison")]
27+
[ValidateLaCode]
2628
public async Task<IActionResult> Comparison([FromQuery] string code, [FromQuery] string[]? set = null, CancellationToken cancellationToken = default)
2729
{
2830
try
@@ -53,6 +55,7 @@ public async Task<IActionResult> Comparison([FromQuery] string code, [FromQuery]
5355
[ProducesResponseType<LocalAuthorityHighNeedsHistoryResponse[]>(StatusCodes.Status200OK)]
5456
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
5557
[Route("history")]
58+
[ValidateLaCode]
5659
public async Task<IActionResult> History([FromQuery] string code, CancellationToken cancellationToken)
5760
{
5861
try

web/src/Web.App/Controllers/LocalAuthorityCensusController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Infrastructure.Apis;
@@ -12,6 +13,7 @@ namespace Web.App.Controllers;
1213
[Controller]
1314
[FeatureGate(FeatureFlags.LocalAuthorities)]
1415
[Route("local-authority/{code}/census")]
16+
[ValidateLaCode]
1517
[LocalAuthorityRequestTelemetry(TrackedRequestFeature.BenchmarkWorkforce)]
1618
public class LocalAuthorityCensusController(
1719
IEstablishmentApi establishmentApi,

web/src/Web.App/Controllers/LocalAuthorityComparisonController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Infrastructure.Apis;
@@ -12,6 +13,7 @@ namespace Web.App.Controllers;
1213
[Controller]
1314
[FeatureGate(FeatureFlags.LocalAuthorities)]
1415
[Route("local-authority/{code}/comparison")]
16+
[ValidateLaCode]
1517
[LocalAuthorityRequestTelemetry(TrackedRequestFeature.BenchmarkCosts)]
1618
public class LocalAuthorityComparisonController(
1719
IEstablishmentApi establishmentApi,

web/src/Web.App/Controllers/LocalAuthorityController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Infrastructure.Apis;
@@ -13,6 +14,7 @@ namespace Web.App.Controllers;
1314
[Controller]
1415
[FeatureGate(FeatureFlags.LocalAuthorities)]
1516
[Route("local-authority/{code}")]
17+
[ValidateLaCode]
1618
public class LocalAuthorityController(
1719
ILogger<LocalAuthorityController> logger,
1820
IEstablishmentApi establishmentApi)

web/src/Web.App/Controllers/LocalAuthorityHighNeedsBenchmarkingController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Extensions;
@@ -15,6 +16,7 @@ namespace Web.App.Controllers;
1516
[Controller]
1617
[FeatureGate(FeatureFlags.LocalAuthorities, FeatureFlags.HighNeeds)]
1718
[Route("local-authority/{code}/high-needs/benchmarking")]
19+
[ValidateLaCode]
1820
public class LocalAuthorityHighNeedsBenchmarkingController(
1921
ILogger<LocalAuthorityHighNeedsBenchmarkingController> logger,
2022
IEstablishmentApi establishmentApi,

web/src/Web.App/Controllers/LocalAuthorityHighNeedsController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Infrastructure.Apis;
@@ -14,6 +15,7 @@ namespace Web.App.Controllers;
1415
[Controller]
1516
[FeatureGate(FeatureFlags.LocalAuthorities, FeatureFlags.HighNeeds)]
1617
[Route("local-authority/{code}/high-needs")]
18+
[ValidateLaCode]
1719
public class LocalAuthorityHighNeedsController(
1820
ILogger<LocalAuthorityHighNeedsController> logger,
1921
IEstablishmentApi establishmentApi,

web/src/Web.App/Controllers/LocalAuthorityHighNeedsHistoricDataController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Domain.LocalAuthorities;
@@ -15,6 +16,7 @@ namespace Web.App.Controllers;
1516
[Controller]
1617
[FeatureGate(FeatureFlags.LocalAuthorities, FeatureFlags.HighNeeds)]
1718
[Route("local-authority/{code}/high-needs/history")]
19+
[ValidateLaCode]
1820
public class LocalAuthorityHighNeedsHistoricDataController(
1921
ILogger<LocalAuthorityHighNeedsHistoricDataController> logger,
2022
IEstablishmentApi establishmentApi,

web/src/Web.App/Controllers/LocalAuthorityHighNeedsNationalRankingsController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http.Extensions;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.FeatureManagement.Mvc;
4+
using Web.App.Attributes;
45
using Web.App.Attributes.RequestTelemetry;
56
using Web.App.Domain;
67
using Web.App.Infrastructure.Apis;
@@ -14,6 +15,7 @@ namespace Web.App.Controllers;
1415
[Controller]
1516
[FeatureGate(FeatureFlags.LocalAuthorities, FeatureFlags.HighNeeds)]
1617
[Route("local-authority/{code}/high-needs/national-rank")]
18+
[ValidateLaCode]
1719
public class LocalAuthorityHighNeedsNationalRankingsController(
1820
ILogger<LocalAuthorityHighNeedsNationalRankingsController> logger,
1921
IEstablishmentApi establishmentApi,

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/Search/WhenViewingLocalAuthoritySearch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class WhenViewingLocalAuthoritySearch(SchoolBenchmarkingWebAppClient clie
1818
[
1919
new LocalAuthoritySummary
2020
{
21-
Code = "123456",
21+
Code = "123",
2222
Name = "LA Name 1"
2323
},
2424
new LocalAuthoritySummary
2525
{
26-
Code = "654321",
26+
Code = "654",
2727
Name = "LA Name 2"
2828
}
2929
]

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/Search/WhenViewingLocalAuthoritySearchResults.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class WhenViewingLocalAuthoritySearchResults(SchoolBenchmarkingWebAppClie
1818
[
1919
new LocalAuthoritySummary
2020
{
21-
Code = "123456",
21+
Code = "123",
2222
Name = "LA Name 1"
2323
},
2424
new LocalAuthoritySummary
2525
{
26-
Code = "654321",
26+
Code = "654",
2727
Name = "LA Name 2"
2828
}
2929
]
@@ -131,7 +131,7 @@ public async Task CanPaginateSearch()
131131
[Fact]
132132
public async Task CanSelectSearchResult()
133133
{
134-
const string code = "123456";
134+
const string code = "123";
135135
var page = await Client
136136
.SetupEstablishment(SearchResults)
137137
.Navigate(Paths.LocalAuthoritySearchResults());

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingHighNeedsBenchmarking.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public async Task CanDisplayNotFoundForSet()
4949

5050
private async Task<(IHtmlDocument page, LocalAuthority authority, string[] set)> SetupNavigateInitPage(string[]? comparatorSet = null)
5151
{
52-
var authority = Fixture.Build<LocalAuthority>().Create();
52+
var authority = Fixture.Build<LocalAuthority>()
53+
.With(a => a.Code, "123")
54+
.Create();
5355
var set = comparatorSet ?? Fixture.Build<string>().CreateMany().ToArray();
5456

5557
var page = await Client.SetupEstablishment(authority)

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingHighNeedsDashboard.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public async Task CanDisplayNotFound()
108108
bool notInRanking = false)
109109
{
110110
var authority = Fixture.Build<LocalAuthority>()
111+
.With(a => a.Code, "123")
111112
.Create();
112113

113114
var rankings = Fixture.Build<LocalAuthorityRank>()

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingHighNeedsHistoricData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public async Task CanDisplayNotFound()
4747
LocalAuthority<HighNeeds>[]? highNeeds)> SetupNavigateInitPage(bool hasHighNeeds = true)
4848
{
4949
var authority = Fixture.Build<LocalAuthority>()
50+
.With(a => a.Code, "123")
5051
.Create();
5152

5253
var highNeeds = hasHighNeeds ? Fixture.Build<LocalAuthority<HighNeeds>>().CreateMany().ToArray() : [];

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingHighNeedsStartBenchmarking.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,17 @@ public async Task CanCancel(string referrer)
177177
private async Task<(IHtmlDocument page, LocalAuthorityStatisticalNeighbours authority, LocalAuthority[] authorities)> SetupNavigateInitPage(string[]? comparators = null, string? referrer = null)
178178
{
179179
var authority = Fixture.Build<LocalAuthorityStatisticalNeighbours>()
180+
.With(a => a.Code, "123")
180181
.Create();
181182

182183
var statisticalNeighbours = Fixture.Build<LocalAuthorityStatisticalNeighbour>()
183184
.CreateMany()
184185
.ToArray();
185186

187+
var random = new Random();
186188
authority.StatisticalNeighbours = statisticalNeighbours;
187189
var authorities = Fixture.Build<LocalAuthority>()
188-
.With(l => l.Code, () => Fixture.Create<string>().Replace("-", string.Empty))
190+
.With(l => l.Code, () => random.Next(100, 999).ToString())
189191
.CreateMany()
190192
.ToArray();
191193

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingHome.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ public async Task CanDisplayNotFound()
116116
DocumentAssert.AssertPageUrl(page, Paths.LocalAuthorityHome(code).ToAbsolute(), HttpStatusCode.NotFound);
117117
}
118118

119+
[Fact]
120+
public async Task CanDisplayBadRequest()
121+
{
122+
const string code = "1234";
123+
var page = await Client
124+
.Navigate(Paths.LocalAuthorityHome(code));
125+
126+
PageAssert.IsNotFoundPage(page);
127+
DocumentAssert.AssertPageUrl(page, Paths.LocalAuthorityHome(code).ToAbsolute(), HttpStatusCode.BadRequest);
128+
}
129+
119130
[Fact]
120131
public async Task CanDisplayProblemWithService()
121132
{
@@ -130,6 +141,7 @@ public async Task CanDisplayProblemWithService()
130141
private async Task<(IHtmlDocument page, LocalAuthority authority, LocalAuthoritySchool[] schools)> SetupNavigateInitPage(bool filteredSearchFeatureEnabled = false, params string[] phaseTypes)
131142
{
132143
var authority = Fixture.Build<LocalAuthority>()
144+
.With(a => a.Code, "123")
133145
.Create();
134146

135147
string[] disabledFlags = [];

web/tests/Web.Integration.Tests/Pages/LocalAuthorities/WhenViewingResources.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public async Task CanDisplayProblemWithService()
5454
private async Task<(IHtmlDocument page, LocalAuthority authority)> SetupNavigateInitPage()
5555
{
5656
var authority = Fixture.Build<LocalAuthority>()
57+
.With(a => a.Code, "123")
5758
.Create();
5859

5960
var page = await Client.SetupEstablishment(authority)

web/tests/Web.Integration.Tests/Proxy/WhenRequestingEducationHealthCarePlansComparison.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class WhenEducationHealthCarePlansComparison(SchoolBenchmarkingWebAppClie
1313
[Fact]
1414
public async Task CanReturnCorrectResponseWhenComparatorSetExists()
1515
{
16-
const string code = nameof(code);
17-
var set = new[] { "code2", "code3" };
16+
const string code = "123";
17+
var set = new[] { "456", "789" };
1818

1919
var plans = new[] { code }
2020
.Concat(set)
@@ -58,7 +58,7 @@ public async Task CanReturnCorrectResponseWhenComparatorSetExists()
5858
[Fact]
5959
public async Task CanReturnNotFoundWhenComparatorSetDoesNotExist()
6060
{
61-
const string code = nameof(code);
61+
const string code = "123";
6262
string[] set = [];
6363

6464
var response = await client
@@ -70,8 +70,8 @@ public async Task CanReturnNotFoundWhenComparatorSetDoesNotExist()
7070
[Fact]
7171
public async Task CanReturnInternalServerError()
7272
{
73-
const string code = nameof(code);
74-
var set = new[] { "code2", "code3" };
73+
const string code = "123";
74+
var set = new[] { "456", "789" };
7575

7676
var response = await client
7777
.SetupEducationHealthCarePlansWithException()

web/tests/Web.Integration.Tests/Proxy/WhenRequestingEducationHealthCarePlansHistory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class WhenEducationHealthCarePlansHistory(SchoolBenchmarkingWebAppClient
1414
[Fact]
1515
public async Task CanReturnCorrectResponse()
1616
{
17-
const string code = nameof(code);
17+
const string code = "123";
1818
const int startYear = 2021;
1919
const int endYear = 2022;
2020

@@ -72,7 +72,7 @@ public async Task CanReturnCorrectResponse()
7272
[Fact]
7373
public async Task CanReturnInternalServerError()
7474
{
75-
const string code = nameof(code);
75+
const string code = "123";
7676
var response = await client
7777
.SetupEducationHealthCarePlansWithException()
7878
.Get(Paths.ApiEducationHealthCarePlansHistory(code));

web/tests/Web.Integration.Tests/Proxy/WhenRequestingHighNeedsComparison.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class WhenRequestingHighNeedsComparison(SchoolBenchmarkingWebAppClient cl
1414
[Fact]
1515
public async Task CanReturnCorrectResponse()
1616
{
17-
const string code = nameof(code);
17+
const string code = "123";
1818
var set = new[] { "code2", "code3" };
1919

2020
var localAuthorities = new[] { code }
@@ -51,7 +51,7 @@ public async Task CanReturnCorrectResponse()
5151
[Fact]
5252
public async Task CanReturnNotFoundWhenComparatorSetDoesNotExist()
5353
{
54-
const string code = nameof(code);
54+
const string code = "123";
5555
string[] set = [];
5656

5757
var response = await client
@@ -63,8 +63,8 @@ public async Task CanReturnNotFoundWhenComparatorSetDoesNotExist()
6363
[Fact]
6464
public async Task CanReturnInternalServerError()
6565
{
66-
const string code = nameof(code);
67-
var set = new[] { "code2", "code3" };
66+
const string code = "123";
67+
var set = new[] { "456", "789" };
6868

6969
var response = await client
7070
.SetupLocalAuthoritiesWithException()

web/tests/Web.Integration.Tests/Proxy/WhenRequestingHighNeedsHistory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public async Task CanReturnCorrectResponse()
1919
.With(h => h.StartYear, 2021)
2020
.With(h => h.EndYear, 2022)
2121
.Create();
22-
const string sort = nameof(sort);
22+
const string code = "123";
2323
var response = await client
2424
.SetupHighNeeds(null, history)
25-
.Get(Paths.ApiHighNeedsHistory(sort));
25+
.Get(Paths.ApiHighNeedsHistory(code));
2626

2727
Assert.IsType<HttpResponseMessage>(response);
2828
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -42,10 +42,10 @@ public async Task CanReturnCorrectResponse()
4242
[Fact]
4343
public async Task CanReturnInternalServerError()
4444
{
45-
const string sort = nameof(sort);
45+
const string code = "123";
4646
var response = await client
4747
.SetupLocalAuthoritiesWithException()
48-
.Get(Paths.ApiHighNeedsHistory(sort));
48+
.Get(Paths.ApiHighNeedsHistory(code));
4949

5050
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
5151
}

0 commit comments

Comments
 (0)