Skip to content

Commit

Permalink
Merge pull request #936 from Klantinteractie-Servicesysteem/feature/V…
Browse files Browse the repository at this point in the history
…erplaatsenvanOnderwerpLinks#805

PC-362 verplaatsen van onderwerp links
  • Loading branch information
mstokericatt authored Nov 8, 2024
2 parents d793e1b + 2a9bcf0 commit 9288476
Show file tree
Hide file tree
Showing 22 changed files with 820 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Kiss.Bff.Test/AuthorizationCheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Kiss.Bff.Beheer.Verwerking;
using Kiss.Bff.Intern.Links.Features;
using Kiss.Bff.Intern.Gespreksresultaten.Features;
using Kiss.Bff.Extern.ZaakGerichtWerken.Contactmomenten;
using Kiss.Bff.Intern.ContactmomentDetails.Features;

namespace Kiss.Bff.Test
{
Expand Down
6 changes: 3 additions & 3 deletions Kiss.Bff.Test/GetFaqTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Faq;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Kiss.Bff.Intern.ContactmomentDetails.Data.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -31,13 +31,13 @@ public async Task Get_ReturnsTopQuestions()
// Arrange
var controller = new GetFaq(dbContext);

var testData = new List<ContactmomentDetailsModel>();
var testData = new List<ContactmomentDetails>();
var topQuestionsCount = 10;

// Add 500 questions
for (int i = 1; i <= 500; i++)
{
testData.Add(new ContactmomentDetailsModel
testData.Add(new ContactmomentDetails
{
Id = i.ToString(),
Vraag = $"Question {i}",
Expand Down
29 changes: 6 additions & 23 deletions Kiss.Bff.Test/ReadContactmomentenDetailsTests.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
using System;
using System.Linq.Expressions;
using System.Security.Claims;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Intern.ContactmomentDetails.Data.Entities;
using Kiss.Bff.Intern.ContactmomentDetails.Features;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Kiss.Bff.Test
{
[TestClass]
public class ReadContactmomentenDetailsTests : TestHelper
{
private IServiceProvider? _serviceProvider;

[TestInitialize]
public void Initialize()
{
InitializeDatabase();
SeedTestData();

var services = new ServiceCollection();
var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, "testuser"),
new Claim(ClaimTypes.Role, Policies.RedactiePolicy)
}));
services.AddSingleton<IHttpContextAccessor>(_ => new HttpContextAccessor { HttpContext = new DefaultHttpContext { User = user } });
_serviceProvider = services.BuildServiceProvider();
}

[TestCleanup]
Expand All @@ -43,7 +26,7 @@ public void Cleanup()
private void SeedTestData()
{
using var dbContext = new BeheerDbContext(_dbContextOptions);
var contactmoment1 = new ContactmomentDetailsModel
var contactmoment1 = new ContactmomentDetails
{
Id = "1",
Startdatum = DateTime.Now,
Expand All @@ -52,7 +35,7 @@ private void SeedTestData()
Vraag = "Question 1"
};

var contactmoment2 = new ContactmomentDetailsModel
var contactmoment2 = new ContactmomentDetails
{
Id = "2",
Startdatum = DateTime.Now,
Expand Down Expand Up @@ -80,7 +63,7 @@ public async Task Get_ValidId_ReturnsOk()
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var contactmoment = result.Value as ContactmomentDetailsModel;
var contactmoment = result.Value as ContactmomentDetailsDetailModel;
Assert.IsNotNull(contactmoment);
Assert.AreEqual(validId, contactmoment.Id);
}
Expand Down
35 changes: 25 additions & 10 deletions Kiss.Bff.Test/WriteContactmomentDetailsTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Kiss.Bff.Intern.ContactmomentDetails.Features;
using ContactmomentDetails = Kiss.Bff.Intern.ContactmomentDetails.Data.Entities.ContactmomentDetails;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Kiss.Bff.Intern.ContactmomentDetails.Data.Entities;

namespace Kiss.Bff.Test
{
Expand Down Expand Up @@ -36,7 +37,8 @@ public async Task Post_ValidModel_ReturnsOk()
Einddatum = DateTime.Now.AddHours(1),
Gespreksresultaat = "Result 1",
Vraag = "Question 1",
EmailadresKcm = "[email protected]" // User.GetEmail()
EmailadresKcm = "[email protected]", // User.GetEmail()
Bronnen = new[] {new ContactmomentDetailsBronModel { Soort = "Soort", Titel = "Titel", Url = "Url" } }
};

// Act
Expand All @@ -47,9 +49,12 @@ public async Task Post_ValidModel_ReturnsOk()
//Assert.AreEqual(200, result.StatusCode);

// Check if the model is added to the database
var addedModel = await dbContext.ContactMomentDetails.FirstOrDefaultAsync();
Assert.IsNotNull(addedModel);
Assert.AreEqual(validModel.Id, addedModel.Id);
var addedEntity = await dbContext.ContactMomentDetails.Include(x=> x.Bronnen).FirstOrDefaultAsync();
var addedBron = addedEntity?.Bronnen.FirstOrDefault();
Assert.IsNotNull(addedEntity);
Assert.IsNotNull(addedBron);
Assert.AreEqual(validModel.Id, addedEntity.Id);
Assert.AreEqual(validModel.Bronnen.First().Titel, addedBron.Titel);
}


Expand All @@ -58,14 +63,20 @@ public async Task Post_ModelWithExistingId_UpdatesExistingEntity()
{
// Arrange
using var dbContext = new BeheerDbContext(_dbContextOptions);
var existingEntity = new ContactmomentDetailsModel
var existingEntity = new ContactmomentDetails
{
Id = "1",
Startdatum = DateTime.Now,
Einddatum = DateTime.Now.AddHours(1),
Gespreksresultaat = "Result 1",
Vraag = "Question 1",
EmailadresKcm = "[email protected]"
EmailadresKcm = "[email protected]",
Bronnen = new List<ContactmomentDetailsBron> { new ContactmomentDetailsBron
{
Titel = "Titel1",
Soort = "Soort1",
Url = "Url1"
} }
};
dbContext.ContactMomentDetails.Add(existingEntity);
dbContext.SaveChanges();
Expand All @@ -78,7 +89,8 @@ public async Task Post_ModelWithExistingId_UpdatesExistingEntity()
Einddatum = DateTime.Now.AddHours(1),
Gespreksresultaat = "Result 2",
Vraag = "Question 2",
EmailadresKcm = "[email protected]"
EmailadresKcm = "[email protected]",
Bronnen = new[] {new ContactmomentDetailsBronModel { Soort = "Soort2", Url = "Url2", Titel = "Titel2" } }
};

// Act
Expand All @@ -89,9 +101,12 @@ public async Task Post_ModelWithExistingId_UpdatesExistingEntity()
Assert.AreEqual(200, result.StatusCode);

// Check if the entity was updated in the database
var updatedEntity = await dbContext.ContactMomentDetails.FindAsync(model.Id);
var updatedEntity = await dbContext.ContactMomentDetails.Include(x=> x.Bronnen).FirstOrDefaultAsync(x=> x.Id == model.Id);
var updatedBron = updatedEntity?.Bronnen?.FirstOrDefault();
Assert.IsNotNull(updatedEntity);
Assert.IsNotNull(updatedBron);
Assert.AreEqual(model.Gespreksresultaat, updatedEntity.Gespreksresultaat);
Assert.AreEqual(model.Bronnen.First().Titel, updatedBron.Titel);
}
}
}
Expand Down
52 changes: 0 additions & 52 deletions Kiss.Bff.Test/ZaakGerichtWerkenUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.ZaakGerichtWerken;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using Moq;

namespace Kiss.Bff.Test
{
Expand Down Expand Up @@ -86,51 +80,5 @@ public void GenerateToken_ReturnsValidToken()
var principal = tokenHandler.ValidateToken(token, validationParameters, out _);
Assert.IsNotNull(principal);
}

[TestMethod]
public async Task Post_AddsOrUpdatesContactmomentToDatabase()
{
// Arrange
var cancellationToken = CancellationToken.None;
var model = new ContactmomentDetailsModel
{
Id = "1",
Startdatum = DateTimeOffset.Now,
Einddatum = DateTimeOffset.Now.AddDays(1),
Gespreksresultaat = "Success",
Vraag = "Question",
SpecifiekeVraag = "Topic",
EmailadresKcm = "[email protected]"
};
var dbContextMock = new Mock<BeheerDbContext>(_dbContextOptions) { CallBase = true };
dbContextMock.Setup(db => db.SaveChangesAsync(cancellationToken)).Returns(Task.FromResult(1));

var userClaims = new[]
{
new Claim(ClaimTypes.Email, "[email protected]")
};
var user = new ClaimsPrincipal(new ClaimsIdentity(userClaims));
var controller = new ContactmomentDetailsToevoegen(dbContextMock.Object)
{
ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext
{
User = user
}
}
};


// Act
var result = await controller.Post(model, cancellationToken);

// Assert
dbContextMock.Verify(db => db.AddAsync(model, cancellationToken), Times.Once);
dbContextMock.Verify(db => db.SaveChangesAsync(cancellationToken), Times.Once);
Assert.IsInstanceOfType(result, typeof(OkResult));
}


}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;

namespace Kiss.Bff.Intern.ContactmomentDetails.Data.Entities
{
public class ContactmomentDetails
{
public string Id { get; set; } = default!;
public DateTimeOffset Startdatum { get; set; }
public DateTimeOffset Einddatum { get; set; }
public string? Gespreksresultaat { get; set; }
public string? Vraag { get; set; }
public string? SpecifiekeVraag { get; set; }
public string? EmailadresKcm { get; set; }
public string? VerantwoordelijkeAfdeling { get; set; }

public List<ContactmomentDetailsBron> Bronnen { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Kiss.Bff.Intern.ContactmomentDetails.Data.Entities
{
public class ContactmomentDetailsBron
{
public int Id { get; set; }

public string ContactmomentDetailsId { get; set; } = default!;

public string Soort { get; set; } = string.Empty;

public string Titel { get; set; } = string.Empty;

public string Url { get; set; } = string.Empty;

public ContactmomentDetails ContactmomentDetails { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace Kiss.Bff.ZaakGerichtWerken.Contactmomenten
namespace Kiss.Bff.Intern.ContactmomentDetails.Features
{
public class ContactmomentDetailsModel
{
Expand All @@ -15,5 +15,7 @@ public class ContactmomentDetailsModel
public string? SpecifiekeVraag { get; set; }
public string? EmailadresKcm { get; set; }
public string? VerantwoordelijkeAfdeling { get; set; }

public IEnumerable<ContactmomentDetailsBronModel> Bronnen { get; set; } = Enumerable.Empty<ContactmomentDetailsBronModel>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;

namespace Kiss.Bff.Intern.ContactmomentDetails.Features
{
public class ContactmomentDetailsBronModel
{
[Required]
public string Soort { get; set; } = "";
[Required]
public string Titel { get; set; } = "";
[Required]
public string Url { get; set; } = "";
}
}
Loading

0 comments on commit 9288476

Please sign in to comment.