Skip to content

Commit

Permalink
Merge pull request #5346 from dfe-analytical-services/dev
Browse files Browse the repository at this point in the history
Merge Dev into Master
  • Loading branch information
N-moh authored Oct 21, 2024
2 parents 8e23989 + 1e48b71 commit 2e96be5
Show file tree
Hide file tree
Showing 230 changed files with 6,418 additions and 9,406 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.202",
"version": "8.0.402",
"rollForward": "latestMajor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ module apiContainerAppModule '../../components/containerApp.bicep' = {

output containerAppFqdn string = apiContainerAppModule.outputs.containerAppFqdn
output containerAppName string = apiContainerAppModule.outputs.containerAppName
output containerAppHealthProbeRelativeUrl string = '/docs'
output containerAppHealthProbeRelativeUrl string = '/health'
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#nullable enable
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using GovUk.Education.ExploreEducationStatistics.Admin.Requests;
using GovUk.Education.ExploreEducationStatistics.Admin.Security;
using GovUk.Education.ExploreEducationStatistics.Admin.Tests.Fixture;
using GovUk.Education.ExploreEducationStatistics.Admin.Validators;
using GovUk.Education.ExploreEducationStatistics.Admin.ViewModels;
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Extensions;
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures;
using GovUk.Education.ExploreEducationStatistics.Content.Model;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Database;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Tests.Fixtures;
using Microsoft.EntityFrameworkCore;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Tests.Controllers.Api;

Expand All @@ -23,12 +22,11 @@ public class CreatePublicationTests(TestApplicationFactory testApp) : Publicatio
[Fact]
public async Task Success()
{
Topic topic = DataFixture.DefaultTopic()
.WithTheme(DataFixture.DefaultTheme());
var theme = DataFixture.DefaultTheme().Generate();

await TestApp.AddTestData<ContentDbContext>(context =>
{
context.Topics.Add(topic);
context.Themes.Add(theme);
});

var request = new PublicationCreateRequest
Expand All @@ -42,7 +40,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
ContactName = "Contact",
ContactTelNo = "01234567890"
},
TopicId = topic.Id
ThemeId = theme.Id
};

var response = await CreatePublication(request);
Expand All @@ -57,10 +55,8 @@ await TestApp.AddTestData<ContentDbContext>(context =>
() => Assert.Equal(request.Contact.TeamEmail, result.Contact.TeamEmail),
() => Assert.Equal(request.Contact.ContactName, result.Contact.ContactName),
() => Assert.Equal(request.Contact.ContactTelNo, result.Contact.ContactTelNo),
() => Assert.Equal(topic.Id, result.Topic.Id),
() => Assert.Equal(topic.Title, result.Topic.Title),
() => Assert.Equal(topic.Theme.Id, result.Theme.Id),
() => Assert.Equal(topic.Theme.Title, result.Theme.Title),
() => Assert.Equal(theme.Id, result.Theme.Id),
() => Assert.Equal(theme.Title, result.Theme.Title),
() => Assert.Null(result.SupersededById),
() => Assert.False(result.IsSuperseded)
);
Expand All @@ -69,8 +65,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>

var saved = await context.Publications
.Include(p => p.Contact)
.Include(p => p.Topic)
.ThenInclude(t => t.Theme)
.Include(p => p.Theme)
.SingleAsync(p => p.Id == result.Id);

Assert.Multiple(
Expand All @@ -81,27 +76,23 @@ await TestApp.AddTestData<ContentDbContext>(context =>
() => Assert.Equal(request.Contact.TeamEmail, saved.Contact.TeamEmail),
() => Assert.Equal(request.Contact.ContactName, saved.Contact.ContactName),
() => Assert.Equal(request.Contact.ContactTelNo, saved.Contact.ContactTelNo),
() => Assert.Equal(topic.Id, saved.Topic.Id),
() => Assert.Equal(topic.Title, saved.Topic.Title),
() => Assert.Equal(topic.Theme.Id, saved.Topic.Theme.Id),
() => Assert.Equal(topic.Theme.Title, saved.Topic.Theme.Title)
() => Assert.Equal(theme.Id, saved.Theme.Id),
() => Assert.Equal(theme.Title, saved.Theme.Title)
);
}

[Fact]
public async Task PublicationSlugNotUnique_ReturnsValidationError()
{
Publication publication = DataFixture.DefaultPublication()
.WithTopic(DataFixture.DefaultTopic()
.WithTheme(DataFixture.DefaultTheme()));
var publication = DataFixture.DefaultPublication()
.WithTheme(DataFixture.DefaultTheme()).Generate();

Topic topic = DataFixture.DefaultTopic()
.WithTheme(DataFixture.DefaultTheme());
var theme = DataFixture.DefaultTheme().Generate();

await TestApp.AddTestData<ContentDbContext>(context =>
{
context.Publications.Add(publication);
context.Topics.Add(topic);
context.Themes.Add(theme);
});

var request = new PublicationCreateRequest
Expand All @@ -116,7 +107,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
ContactName = "Contact",
ContactTelNo = "01234567890"
},
TopicId = topic.Id
ThemeId = theme.Id
};

var response = await CreatePublication(request);
Expand All @@ -135,12 +126,11 @@ await TestApp.AddTestData<ContentDbContext>(context =>
[Fact]
public async Task UserHasNoAccessToCreatePublication_ReturnsForbidden()
{
Topic topic = DataFixture.DefaultTopic()
.WithTheme(DataFixture.DefaultTheme());
var theme = DataFixture.DefaultTheme().Generate();

await TestApp.AddTestData<ContentDbContext>(context =>
{
context.Topics.Add(topic);
context.Themes.Add(theme);
});

var request = new PublicationCreateRequest
Expand All @@ -154,7 +144,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
ContactName = "Contact",
ContactTelNo = "01234567890"
},
TopicId = topic.Id
ThemeId = theme.Id
};

var client = TestApp
Expand All @@ -170,12 +160,10 @@ private async Task<HttpResponseMessage> CreatePublication(
PublicationCreateRequest request,
HttpClient? client = null)
{
var user = DataFixture
.AuthenticatedUser()
.WithClaim(SecurityClaimTypes.CreateAnyPublication.ToString());

client ??= TestApp
.SetUser(user)
.SetUser(DataFixture
.AuthenticatedUser()
.WithClaim(SecurityClaimTypes.CreateAnyPublication.ToString()))
.CreateClient();

return await client.PostAsJsonAsync("api/publications", request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GovUk.Education.ExploreEducationStatistics.Admin.Controllers.Api;
using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces;
using GovUk.Education.ExploreEducationStatistics.Admin.ViewModels;
using Moq;
using Xunit;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Tests.Controllers.Api
{
Expand Down Expand Up @@ -41,13 +40,6 @@ public async Task GetThemes_Returns_Ok()
new ThemeViewModel
{
Title = "Theme A",
Topics = new List<TopicViewModel>
{
new TopicViewModel
{
Title = "Topic A"
}
}
}
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces;
using GovUk.Education.ExploreEducationStatistics.Admin.Services.ManageContent;
Expand All @@ -18,6 +13,11 @@
using GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Moq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using static GovUk.Education.ExploreEducationStatistics.Admin.Tests.Services.DbUtils;
using static GovUk.Education.ExploreEducationStatistics.Common.Model.FileType;
using static GovUk.Education.ExploreEducationStatistics.Common.Model.TimeIdentifier;
Expand Down Expand Up @@ -68,19 +68,16 @@ public async Task GetManageContentPageViewModel()
},
Slug = "test-publication",
Title = "Publication",
Topic = new Topic
Theme = new Theme
{
Theme = new Theme
{
Title = "Theme"
}
Title = "Theme"
}
};

var releaseVersion = new ReleaseVersion
{
Id = releaseVersionId,
NextReleaseDate = new PartialDate {Day = "9", Month = "9", Year = "2040"},
NextReleaseDate = new PartialDate { Day = "9", Month = "9", Year = "2040" },
PreReleaseAccessList = "Test access list",
Publication = publication,
Release = new Release { Id = releaseId },
Expand Down Expand Up @@ -147,7 +144,7 @@ public async Task GetManageContentPageViewModel()

var otherReleaseVersion = new ReleaseVersion
{
NextReleaseDate = new PartialDate {Day = "8", Month = "8", Year = "2040"},
NextReleaseDate = new PartialDate { Day = "8", Month = "8", Year = "2040" },
Publication = publication,
PublishScheduled = DateTime.Parse("2020-08-07T23:00:00.00Z", styles: DateTimeStyles.AdjustToUniversal),
Published = null,
Expand Down Expand Up @@ -377,9 +374,6 @@ public async Task GetManageContentPageViewModel()
Assert.Null(contentPublication.ExternalMethodology);
Assert.Equal("test-publication", contentPublication.Slug);
Assert.Equal("Publication", contentPublication.Title);
Assert.Equal("Theme", contentPublication.Topic.Theme.Title);
Assert.NotNull(contentPublication.Topic);
Assert.NotNull(contentPublication.Topic.Theme);

var contentPublicationReleaseSeries = contentPublication.ReleaseSeries;
Assert.Equal(3, contentPublicationReleaseSeries.Count);
Expand Down Expand Up @@ -426,15 +420,12 @@ public async Task GetManageContentPageViewModel_IsPrerelease()
Contact = new Contact(),
Slug = "test-publication",
Title = "Publication",
Topic = new Topic
{
Theme = new Theme(),
}
Theme = new Theme()
};

var releaseVersion = new ReleaseVersion
{
NextReleaseDate = new PartialDate {Day = "9", Month = "9", Year = "2040"},
NextReleaseDate = new PartialDate { Day = "9", Month = "9", Year = "2040" },
PreReleaseAccessList = "Test access list",
Publication = publication,
PublishScheduled = DateTime.Parse("2020-09-08T23:00:00.00Z", styles: DateTimeStyles.AdjustToUniversal),
Expand Down Expand Up @@ -592,12 +583,9 @@ public async Task GetManageContentPageViewModel_MapsBlocksCorrectly()
},
Slug = "test-publication",
Title = "Publication",
Topic = new Topic
Theme = new Theme
{
Theme = new Theme
{
Title = "Theme"
}
Title = "Theme"
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Threading.Tasks;
using GovUk.Education.ExploreEducationStatistics.Admin.Security;
using GovUk.Education.ExploreEducationStatistics.Admin.Services.ManageContent;
using GovUk.Education.ExploreEducationStatistics.Admin.ViewModels;
Expand All @@ -11,6 +9,8 @@
using GovUk.Education.ExploreEducationStatistics.Content.Model.Database;
using Microsoft.AspNetCore.Mvc;
using Moq;
using System;
using System.Threading.Tasks;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Tests.Services.ManageContent
{
Expand Down Expand Up @@ -45,10 +45,9 @@ public void DeleteRelatedInformationAsync()
public void UpdateRelatedInformationAsync()
{
AssertSecurityPoliciesChecked(service =>
service.UpdateRelatedInformationAsync(
releaseVersionId: _releaseVersion.Id,
relatedInformationId: Guid.NewGuid(),
new CreateUpdateLinkRequest()),
service.UpdateRelatedInformation(
_releaseVersion.Id,
[]),
SecurityPolicies.CanUpdateSpecificRelease);
}

Expand Down
Loading

0 comments on commit 2e96be5

Please sign in to comment.