-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into snyk-upgrade-c977d5ac5809b59b77a95133c0541f46
- Loading branch information
Showing
75 changed files
with
3,201 additions
and
1,608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
**/.dockerignore | ||
**/.env.local | ||
**/.env.local.example | ||
**/.git | ||
**/.github | ||
**/.gitignore | ||
**/dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
|
||
|
||
|
@@ -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(); | ||
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
@@ -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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
Kiss.Bff/Extern/ZaakGerichtWerken/Contactmomenten/ContactmomentDetailsDetails.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.