Skip to content

Commit 7640ccf

Browse files
authored
Merge pull request #5073 from dfe-analytical-services/dev
Merge Dev into Master
2 parents 6aa5bac + 9accb42 commit 7640ccf

File tree

100 files changed

+7992
-1135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+7992
-1135
lines changed

src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Controllers/Api/Public.Data/DataSetVersionsControllerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ await TestApp.AddTestData<PublicDataDbContext>(context =>
8383
context.DataSets.Update(savedDataSet);
8484
});
8585

86-
return new CreateDataSetResponseViewModel
86+
return new ProcessDataSetVersionResponseViewModel
8787
{
8888
DataSetId = dataSet.Id,
8989
DataSetVersionId = nextVersion.Id,

src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Controllers/Api/Public.Data/DataSetsControllerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ await TestApp.AddTestData<PublicDataDbContext>(context =>
967967
context.DataSets.Update(dataSet);
968968
});
969969

970-
return new CreateDataSetResponseViewModel
970+
return new ProcessDataSetVersionResponseViewModel
971971
{
972972
DataSetId = dataSet.Id,
973973
DataSetVersionId = dataSetVersion.Id,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#nullable enable
2+
using GovUk.Education.ExploreEducationStatistics.Admin.Requests;
3+
using GovUk.Education.ExploreEducationStatistics.Admin.Tests.Fixture;
4+
using GovUk.Education.ExploreEducationStatistics.Admin.ViewModels.Statistics;
5+
using GovUk.Education.ExploreEducationStatistics.Common.Model.Data;
6+
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Extensions;
7+
using GovUk.Education.ExploreEducationStatistics.Data.Model.Database;
8+
using Microsoft.EntityFrameworkCore;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
using System.Linq;
13+
using System.Net.Http;
14+
using System.Net.Http.Json;
15+
using System.Reflection;
16+
using System.Threading.Tasks;
17+
using static GovUk.Education.ExploreEducationStatistics.Admin.Models.GlobalRoles;
18+
using static GovUk.Education.ExploreEducationStatistics.Admin.Tests.Security.Utils.ClaimsPrincipalUtils;
19+
20+
namespace GovUk.Education.ExploreEducationStatistics.Admin.Tests.Controllers.Api.Statistics;
21+
public class BoundaryLevelControllerTests(TestApplicationFactory testApp) : IntegrationTestFixture(testApp)
22+
{
23+
[Fact]
24+
public async Task ListBoundaryLevels_Success()
25+
{
26+
await TestApp.AddTestData<StatisticsDbContext>(context =>
27+
{
28+
context.BoundaryLevel.AddRange(
29+
new()
30+
{
31+
Id = 1,
32+
Created = DateTime.Now,
33+
Label = "Boundary Level 1",
34+
Level = GeographicLevel.Country,
35+
Published = DateTime.Now,
36+
},
37+
new()
38+
{
39+
Id = 2,
40+
Created = DateTime.Now,
41+
Label = "Boundary Level 2",
42+
Level = GeographicLevel.Region,
43+
Published = DateTime.Now,
44+
});
45+
});
46+
47+
var client = TestApp
48+
.SetUser(AuthenticatedUser(RoleClaim(RoleNames.BauUser)))
49+
.CreateClient();
50+
51+
var response = await client.GetAsync("api/boundary-level");
52+
53+
var result = response.AssertOk<List<BoundaryLevelViewModel>>();
54+
55+
Assert.Multiple(
56+
() => Assert.Equal(1, result[0].Id),
57+
() => Assert.Equal(2, result[1].Id),
58+
() => Assert.Equal(GeographicLevel.Country, result[0].Level),
59+
() => Assert.Equal(GeographicLevel.Region, result[1].Level),
60+
() => Assert.Equal("Boundary Level 1", result[0].Label),
61+
() => Assert.Equal("Boundary Level 2", result[1].Label)
62+
);
63+
}
64+
65+
[Fact]
66+
public async Task GetBoundaryLevel_Success()
67+
{
68+
await TestApp.AddTestData<StatisticsDbContext>(context =>
69+
{
70+
context.BoundaryLevel.Add(
71+
new()
72+
{
73+
Id = 1,
74+
Created = DateTime.Now,
75+
Label = "Boundary Level 1",
76+
Level = GeographicLevel.Country,
77+
Published = DateTime.Now,
78+
});
79+
});
80+
81+
var client = TestApp
82+
.SetUser(AuthenticatedUser(RoleClaim(RoleNames.BauUser)))
83+
.CreateClient();
84+
85+
var response = await client.GetAsync("api/boundary-level/1");
86+
87+
var result = response.AssertOk<BoundaryLevelViewModel>();
88+
89+
Assert.Multiple(
90+
() => Assert.Equal(1, result.Id),
91+
() => Assert.Equal("Boundary Level 1", result.Label)
92+
);
93+
}
94+
95+
[Fact]
96+
public async Task UpdateBoundaryLevel_Success()
97+
{
98+
await TestApp.AddTestData<StatisticsDbContext>(context =>
99+
{
100+
context.BoundaryLevel.Add(
101+
new()
102+
{
103+
Id = 1,
104+
Created = DateTime.Now,
105+
Label = "Boundary Level 1",
106+
Level = GeographicLevel.Country,
107+
Published = DateTime.Now,
108+
});
109+
});
110+
111+
var client = TestApp
112+
.SetUser(AuthenticatedUser(RoleClaim(RoleNames.BauUser)))
113+
.CreateClient();
114+
115+
var request = new BoundaryLevelUpdateRequest
116+
{
117+
Id = 1,
118+
Label = "Updated Boundary Level 1",
119+
};
120+
121+
var response = await client.PatchAsync("api/boundary-level", JsonContent.Create(request));
122+
123+
response.AssertNoContent();
124+
125+
await using var context = TestApp.GetDbContext<StatisticsDbContext>();
126+
127+
var saved = await context.BoundaryLevel.SingleAsync(bl => bl.Id == request.Id);
128+
129+
Assert.Multiple(
130+
() => Assert.Equal(request.Id, saved.Id),
131+
() => Assert.Equal(request.Label, saved.Label),
132+
() => Assert.NotNull(saved.Updated)
133+
);
134+
}
135+
136+
[Fact]
137+
public async Task CreateBoundaryLevel_Success()
138+
{
139+
var client = TestApp
140+
.SetUser(AuthenticatedUser(RoleClaim(RoleNames.BauUser)))
141+
.CreateClient();
142+
143+
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, @"Resources/REG - Regions England BUC 202212.geojson");
144+
var content = new MultipartFormDataContent
145+
{
146+
{ new StringContent("Region"), "level" },
147+
{ new StringContent("Boundary Level 1"), "label" },
148+
{ new StreamContent(File.OpenRead(path)), "file", "REG - Regions England BUC 202212.geojson" },
149+
{ new StringContent("2020-01-01"), "published" },
150+
};
151+
152+
var response = await client.PostAsync("api/boundary-level", content);
153+
154+
response.AssertNoContent();
155+
156+
await using var context = TestApp.GetDbContext<StatisticsDbContext>();
157+
158+
var savedBoundaryLevel = Assert.Single(context.BoundaryLevel.Where(bl => bl.Id == 1));
159+
Assert.Single(context.BoundaryData.Where(bd => bd.Id == 1));
160+
Assert.Equal(GeographicLevel.Region, savedBoundaryLevel.Level);
161+
}
162+
}

0 commit comments

Comments
 (0)