-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for nullability of UserId in Profile API - user contact point…
… lookups (#644) * Declare nullability on properties after changes in Profile API * Revert "Declare nullability on properties after changes in Profile API" This reverts commit d4fadb0. * Introduce a DTO class for UserContactPoints as received from Profile API * Add test for mapping of UserContactPoints DTO -> domain model * Fix build warning: replace NotEmpty -> Contains * Fix warning on pascal-casing by renaming DTO class * Rename files, modify comments * Change file names for real
- Loading branch information
Showing
8 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/Altinn.Notifications.Integrations/Profile/Mappers/UserContactPointsDtoMapperExtension.cs
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Altinn.Notifications.Core.Models.ContactPoints; | ||
using Altinn.Notifications.Integrations.Profile.Models; | ||
|
||
namespace Altinn.Notifications.Integrations.Profile.Mappers; | ||
|
||
/// <summary> | ||
/// Extension class to map user contact points from DTO to domain model | ||
/// </summary> | ||
public static class UserContactPointsDtoMapperExtension | ||
{ | ||
/// <summary> | ||
/// Maps the DTO model to domain model | ||
/// </summary> | ||
/// <param name="userContactPointDto">This DTO object</param> | ||
/// <returns>The UserContactPoints object mapped from this DTO object</returns> | ||
public static UserContactPoints ToUserContactPoint(this UserContactPointsDto userContactPointDto) | ||
{ | ||
return new UserContactPoints | ||
{ | ||
UserId = userContactPointDto.UserId ?? 0, | ||
NationalIdentityNumber = userContactPointDto.NationalIdentityNumber ?? string.Empty, | ||
IsReserved = userContactPointDto.IsReserved, | ||
MobileNumber = userContactPointDto.MobileNumber ?? string.Empty, | ||
Email = userContactPointDto.Email ?? string.Empty | ||
}; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Altinn.Notifications.Integrations/Profile/Models/UserContactPointsDto.cs
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Altinn.Notifications.Integrations.Profile.Models; | ||
|
||
/// <summary> | ||
/// DTO for user contact points received from the ProfileClient, describing the availability of contact points for a user | ||
/// </summary> | ||
public class UserContactPointsDto | ||
{ | ||
/// <summary> | ||
/// Gets or sets the ID of the user | ||
/// </summary> | ||
public int? UserId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the national identityt number of the user | ||
/// </summary> | ||
public string? NationalIdentityNumber { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a boolean indicating whether the user has reserved themselves from electronic communication | ||
/// </summary> | ||
public bool IsReserved { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the mobile number | ||
/// </summary> | ||
public string? MobileNumber { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the email address | ||
/// </summary> | ||
public string? Email { get; set; } | ||
} |
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
64 changes: 64 additions & 0 deletions
64
...ts/Notifications.Integrations/Profile/Mappers/UserContactPointsDtoMapperExtensionTests.cs
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Altinn.Notifications.Integrations.Profile.Mappers; | ||
using Altinn.Notifications.Integrations.Profile.Models; | ||
using Xunit; | ||
|
||
namespace Altinn.Notifications.Tests.Notifications.Integrations.Profile.Mappers; | ||
|
||
public class UserContactPointsDtoMapperExtensionTests | ||
{ | ||
[Fact] | ||
public void ToUserContactPoint_NullValues_MapsCorrectly() | ||
{ | ||
// Arrange | ||
var userContactPointsDTO = new UserContactPointsDto | ||
{ | ||
UserId = null, | ||
NationalIdentityNumber = null, | ||
IsReserved = false, | ||
Email = null, | ||
MobileNumber = null | ||
}; | ||
|
||
// Act | ||
var mappedResult = userContactPointsDTO.ToUserContactPoint(); | ||
|
||
// Assert | ||
Assert.Equal(0, mappedResult.UserId); | ||
Assert.Equal(string.Empty, mappedResult.NationalIdentityNumber); | ||
Assert.False(mappedResult.IsReserved); | ||
Assert.Equal(string.Empty, mappedResult.Email); | ||
Assert.Equal(string.Empty, mappedResult.MobileNumber); | ||
} | ||
|
||
[Fact] | ||
public void ToUserContactPoint_WithValues_MapsCorrectly() | ||
{ | ||
// Arrange | ||
var testData = new | ||
{ | ||
userId = 123, | ||
nationalIdentityNumber = "12345678910", | ||
email = "[email protected]", | ||
isReserved = false, | ||
mobileNumber = "+4712345678" | ||
}; | ||
var userContactPointsDTO = new UserContactPointsDto | ||
{ | ||
UserId = testData.userId, | ||
NationalIdentityNumber = testData.nationalIdentityNumber, | ||
Email = testData.email, | ||
IsReserved = testData.isReserved, | ||
MobileNumber = testData.mobileNumber | ||
}; | ||
|
||
// Act | ||
var mappedResult = userContactPointsDTO.ToUserContactPoint(); | ||
|
||
// Assert | ||
Assert.Equal(testData.userId, mappedResult.UserId); | ||
Assert.Equal(testData.nationalIdentityNumber, mappedResult.NationalIdentityNumber); | ||
Assert.Equal(testData.email, mappedResult.Email); | ||
Assert.Equal(testData.mobileNumber, mappedResult.MobileNumber); | ||
Assert.Equal(testData.isReserved, mappedResult.IsReserved); | ||
} | ||
} |
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