Skip to content

Commit

Permalink
Merge pull request #458 from DFE-Digital/bug/191301/pageEntitySectionId
Browse files Browse the repository at this point in the history
Update section id on interstitial page when mapping section
  • Loading branch information
uahussain12 authored Jan 16, 2024
2 parents 9b8a53a + 880bac8 commit 70093ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Dfe.PlanTech.AzureFunctions/Mappings/SectionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public SectionMapper(CmsDbContext db, ILogger<SectionMapper> logger, JsonSeriali

UpdateReferencesArray(values, "recommendations", _db.RecommendationPages, (id, recommendationPage) => recommendationPage.SectionId = Payload!.Sys.Id);

UpdateInterstitialPage(values);

return values;
}

private void UpdateInterstitialPage(Dictionary<string, object?> values)
{
if (values.TryGetValue("interstitialPageId", out var pageId) && pageId != null)
{
var interstitialPageId = pageId.ToString();

UpdateRelatedEntity(interstitialPageId, _db.Pages, (id, interstitialPage) => interstitialPage.SectionId = Payload!.Sys.Id);

Check warning on line 41 in src/Dfe.PlanTech.AzureFunctions/Mappings/SectionMapper.cs

View workflow job for this annotation

GitHub Actions / Build & Deploy Azure Function to Dev (Dev) / Build & Deploy .NET Azure Function App

Possible null reference argument for parameter 'inner' in 'void JsonToDbMapper<SectionDbEntity>.UpdateRelatedEntity<PageDbEntity>(object inner, DbSet<PageDbEntity> dbSet, Action<string, PageDbEntity> updateEntity)'.
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dfe.PlanTech.AzureFunctions.Mappings;
using Dfe.PlanTech.Domain.Caching.Models;
using Dfe.PlanTech.Domain.Content.Models;
using Dfe.PlanTech.Domain.Questionnaire.Models;
using Dfe.PlanTech.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -35,11 +36,29 @@ public class SectionMapperTests : BaseMapperTests

public SectionMapperTests()
{
PageDbEntity pageDbEntity = new PageDbEntity
{
Id = "Interstitial page id",
};

var list = new List<PageDbEntity>() { pageDbEntity };
IQueryable<PageDbEntity> queryable = list.AsQueryable();

var asyncProvider = new AsyncQueryProvider<PageDbEntity>(queryable.Provider);

var mockPageDataSet = Substitute.For<DbSet<PageDbEntity>, IQueryable<PageDbEntity>>();
((IQueryable<PageDbEntity>)mockPageDataSet).Provider.Returns(asyncProvider);
((IQueryable<PageDbEntity>)mockPageDataSet).Expression.Returns(queryable.Expression);
((IQueryable<PageDbEntity>)mockPageDataSet).ElementType.Returns(queryable.ElementType);
((IQueryable<PageDbEntity>)mockPageDataSet).GetEnumerator().Returns(queryable.GetEnumerator());

_logger = Substitute.For<ILogger<SectionMapper>>();
_mapper = new SectionMapper(_db, _logger, JsonOptions);

_db.Questions = _questionsDbSet;

_db.Pages = mockPageDataSet;

_questionsDbSet.WhenForAnyArgs(questionDbSet => questionDbSet.Attach(Arg.Any<QuestionDbEntity>()))
.Do(callinfo =>
{
Expand Down Expand Up @@ -72,7 +91,7 @@ public void Mapper_Should_Map_Relationship()
Assert.Equal(InterstitialPage.Sys.Id, concrete.InterstitialPageId);

Assert.Equal(Questions.Length, _attachedQuestions.Count);

foreach (var question in Questions)
{
var contains = _attachedQuestions.Any(attached => attached.Id == question.Sys.Id);
Expand Down

0 comments on commit 70093ad

Please sign in to comment.