Skip to content

Commit

Permalink
Merge branch 'main' into #827-Playwright-Test---Stappen-Nieuwswerkins…
Browse files Browse the repository at this point in the history
…tructies-Skills-Filter
  • Loading branch information
felixcicatt authored Dec 16, 2024
2 parents 0cdb2af + 81d8857 commit 2abbfb4
Show file tree
Hide file tree
Showing 89 changed files with 3,887 additions and 2,057 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
**/.dockerignore
**/.env.local
**/.env.local.example
**/.git
**/.github
**/.gitignore
**/dist
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:
# Run Linter against code base #
################################
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.x.x'
dotnet-version: '8.x.x'

- name: Install dotnet-format tool
working-directory: ./Kiss.Bff
Expand Down
12 changes: 8 additions & 4 deletions Kiss.Bff.Test/AuthorizationCheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Kiss.Bff.Beheer.Verwerking;
using Kiss.Bff.Intern.Links.Features;
using Kiss.Bff.Intern.Gespreksresultaten.Features;
using Kiss.Bff.Intern.Seed.Features;
using Kiss.Bff.Intern.ContactmomentDetails.Features;

namespace Kiss.Bff.Test
{
Expand All @@ -40,7 +42,7 @@ public static void ClassCleanup()
s_factory?.Dispose();
}

public static IEnumerable<object[]> GetControllersMethodsWithDefaultAuthorizeAttributes()
public static IEnumerable<object[]> GetControllersMethodsWithRedactiePolicyAuthorizeAttribute()
{
// Define the controllers and methods to test here
var controllersWithMethodsToTest = new List<(Type controllerType, string methodName, Type[] parameterTypes)>
Expand All @@ -54,6 +56,8 @@ public static IEnumerable<object[]> GetControllersMethodsWithDefaultAuthorizeAtt
(typeof(SkillsController), "PutSkill", new[] { typeof(int), typeof(SkillPutModel), typeof(CancellationToken) }),
(typeof(SkillsController), "PostSkill", new[] { typeof(SkillPostModel), typeof(CancellationToken) }),
(typeof(GetVerwerkingsLogs), "Get", new Type[0]),
(typeof(SeedController), "SeedStart", new Type[0]),
(typeof(SeedController), "SeedCheck", new Type[0]),
// Add more controller, method, and parameter combinations as needed
};

Expand All @@ -78,7 +82,7 @@ public async Task CallingEnpointsWithoutCredetialsShouldResultInAUnauthorizedRes
}

[DataTestMethod]
[DynamicData(nameof(GetControllersMethodsWithDefaultAuthorizeAttributes), DynamicDataSourceType.Method)]
[DynamicData(nameof(GetControllersMethodsWithRedactiePolicyAuthorizeAttribute), DynamicDataSourceType.Method)]
public void TestAuthorizeAttribute(Type controllerType, string methodName, Type[] parameterTypes)
{
// Manually create an instance of the controller
Expand Down Expand Up @@ -109,7 +113,7 @@ public void TestAuthorizeAttribute(Type controllerType, string methodName, Type[
[TestMethod]
public void TestAuthorizationOfManagementInformatieEndpoint()
{
var controllerType = typeof(ReadContactmomentenDetails);
var controllerType = typeof(ContactmomentDetailsRapportageOverzicht);

var dbContext = new BeheerDbContext(new DbContextOptions<BeheerDbContext>());
var controller = Activator.CreateInstance(controllerType, dbContext) as ControllerBase;
Expand All @@ -118,7 +122,7 @@ public void TestAuthorizationOfManagementInformatieEndpoint()

var methods = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

Assert.AreEqual(2, methods.Length);
Assert.AreEqual(1, methods.Length);

for (var i = 0; i < methods.Length; i += 1)
{
Expand Down
2 changes: 1 addition & 1 deletion 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
17 changes: 6 additions & 11 deletions Kiss.Bff.Test/Kiss.Bff.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.20" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.29" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.29" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.11" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kiss.Bff\Kiss.Bff.csproj" />
</ItemGroup>

</Project>
</Project>
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 Down Expand Up @@ -70,7 +53,7 @@ public async Task Get_ValidId_ReturnsOk()
{
using var dbContext = new BeheerDbContext(_dbContextOptions);
// Arrange
var controller = new ReadContactmomentenDetails(dbContext);
var controller = new ReadContactmomentDetails(dbContext);
var validId = "1";

// Act
Expand All @@ -80,7 +63,7 @@ public async Task Get_ValidId_ReturnsOk()
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var contactmoment = result.Value as ContactmomentDetails;
var contactmoment = result.Value as ContactmomentDetailsDetailModel;
Assert.IsNotNull(contactmoment);
Assert.AreEqual(validId, contactmoment.Id);
}
Expand All @@ -90,7 +73,7 @@ public async Task Get_InvalidId_ReturnsNotFound()
{
using var dbContext = new BeheerDbContext(_dbContextOptions);
// Arrange
var controller = new ReadContactmomentenDetails(dbContext);
var controller = new ReadContactmomentDetails(dbContext);
var invalidId = "nonexistent";

// Act
Expand Down
41 changes: 28 additions & 13 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 All @@ -28,15 +29,16 @@ public async Task Post_ValidModel_ReturnsOk()
{
using var dbContext = new BeheerDbContext(_dbContextOptions);
// Arrange
var controller = new WriteContactmomentenDetails(dbContext);
var validModel = new ContactmomentDetails
var controller = new ContactmomentDetailsToevoegen(dbContext);
var validModel = new ContactmomentDetailsModel
{
Id = "1",
Startdatum = DateTime.Now,
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 @@ -65,20 +70,27 @@ public async Task Post_ModelWithExistingId_UpdatesExistingEntity()
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();

var controller = new WriteContactmomentenDetails(dbContext);
var model = new ContactmomentDetails
var controller = new ContactmomentDetailsToevoegen(dbContext);
var model = new ContactmomentDetailsModel
{
Id = "1",
Startdatum = DateTime.Now,
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
54 changes: 1 addition & 53 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 @@ -50,7 +44,7 @@ public void Initialize()
public void GenerateToken_ReturnsValidToken()
{
// Arrange
var apiKey = "blablaFakeApiKey";
var apiKey = "blablaFakeApiKeyblablaFakeApiKey";
var clientId = "124567890.87654321";
var userId = "blablaFakeUserId";
var userRepresentation = "blablaFakeUserRepresentation";
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 ContactmomentDetails
{
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 WriteContactmomentenDetails(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));
}


}
}
10 changes: 5 additions & 5 deletions Kiss.Bff.Test/Zaaksysteem/GetZakenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task GetZaken_correctly_proxies_400_status_code()
.Respond(HttpStatusCode.BadRequest);
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters long", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);
Expand All @@ -94,7 +94,7 @@ public async Task GetZaken_correctly_proxies_unreachable_host()

var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters long", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task GetZaken_with_kvknummer_and_rsin_queries_by_rsin_by_default()
.Respond("application/json", "{\"results\": []}");
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters long", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);
Expand All @@ -161,7 +161,7 @@ public async Task GetZaken_with_kvknummer_and_rsin_queries_by_kvknummer_if_speci
.Respond("application/json", "{\"results\": []}");
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, "kvkNummer");
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters long", null, null, "kvkNummer");


var sut = new GetZaken(new[] { config }, clientFactory, logger);
Expand All @@ -181,7 +181,7 @@ private static async Task<IActionResult> RunHappyFlowTest(string baseUrl, String
.Respond("application/json", responseBody);
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters long", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);
Expand Down
Loading

0 comments on commit 2abbfb4

Please sign in to comment.