Skip to content

Commit

Permalink
feat(mail): adjust mailing endpoint
Browse files Browse the repository at this point in the history
Refs: #564
  • Loading branch information
Phil91 committed Apr 4, 2024
1 parent 09132e7 commit ec1fd9b
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task SendMail(MailData mailData)

if (data.RecipientMail is not null)
{
_mailingProcessCreation.CreateMailProcess(data.RecipientMail, mailData.Template, mailData.MailParameters);
_mailingProcessCreation.CreateMailProcess(data.RecipientMail, mailData.Template, mailData.MailParameters.ToDictionary(x => x.Key, x => x.Value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ public MailController(IMailBusinessLogic businessLogic)
}

/// <summary>
/// Creates a notification with the given data
/// Creates a mail from the given data
/// </summary>
/// <param name="data">Data for the notification</param>
/// <param name="data">Data for the mail</param>
/// <returns>Return NoContent</returns>
/// <remarks>Example: POST: /api/notification</remarks>
/// <response code="204">Count of the notifications.</response>
/// <response code="400">NotificationStatus does not exist.</response>
/// <response code="403">IamUserId is not assigned.</response>
[HttpDelete]
/// <remarks>Example: POST: /api/administration/mail</remarks>
[HttpPost]
[Route("")]
[Authorize(Roles = "send_mail")]
// [Authorize(Roles = "send_mail")]
[Authorize(Policy = PolicyTypes.ValidIdentity)]
[ProducesResponseType(typeof(int), StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
Expand Down
7 changes: 6 additions & 1 deletion src/administration/Administration.Service/Models/MailData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
public record MailData(
[property: JsonPropertyName("requester")] Guid Requester,
[property: JsonPropertyName("template")] string Template,
[property: JsonPropertyName("mailParameters")] Dictionary<string, string> MailParameters
[property: JsonPropertyName("mailParameters")] IEnumerable<MailParameter> MailParameters
);

public record MailParameter(
[property: JsonPropertyName("key")] string Key,
[property: JsonPropertyName("value")] string Value
);
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library</AssemblyName>
Expand All @@ -35,8 +35,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="6.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="JsonSchema.Net" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task SendMail_WithUserWithoutEmail_DoesntCallService()
A.CallTo(() => _userRepository.GetUserMailData(UserId)).Returns((true, null));

// Act
await _sut.SendMail(data).ConfigureAwait(false);
await _sut.SendMail(data);

// Assert
A.CallTo(() => _mailingService.CreateMailProcess(A<string>._, A<string>._, A<Dictionary<string, string>>._)).MustNotHaveHappened();
Expand All @@ -67,11 +67,11 @@ public async Task SendMail_WithUserWithoutEmail_DoesntCallService()
public async Task SendMail_WithValid_CallsExpected()
{
// Arrange
var data = new MailData(UserId, "testTemplate", new Dictionary<string, string>());
var data = new MailData(UserId, "testTemplate", Enumerable.Empty<MailParameter>());
A.CallTo(() => _userRepository.GetUserMailData(UserId)).Returns((true, "[email protected]"));

// Act
await _sut.SendMail(data).ConfigureAwait(false);
await _sut.SendMail(data);

// Assert
A.CallTo(() => _mailingService.CreateMailProcess("[email protected]", "testTemplate", A<Dictionary<string, string>>._)).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public async Task ProcessIssuerBpnResponseAsync_WithValidData_CallsExpected()

// Act
var data = new IssuerResponseData(BusinessPartnerNumber, IssuerResponseStatus.SUCCESSFUL, "test Message");
await _logic.ProcessIssuerBpnResponseAsync(data, CancellationToken.None).ConfigureAwait(false);
await _logic.ProcessIssuerBpnResponseAsync(data, CancellationToken.None);

// Assert
A.CallTo(() => _issuerComponentBusinessLogic.StoreBpnlCredential(ApplicationId, data))
Expand Down Expand Up @@ -924,7 +924,7 @@ public async Task ProcessIssuerMembershipResponseAsync_WithValidData_CallsExpect

// Act
var data = new IssuerResponseData(BusinessPartnerNumber, IssuerResponseStatus.SUCCESSFUL, "test Message");
await _logic.ProcessIssuerMembershipResponseAsync(data, CancellationToken.None).ConfigureAwait(false);
await _logic.ProcessIssuerMembershipResponseAsync(data, CancellationToken.None);

// Assert
A.CallTo(() => _issuerComponentBusinessLogic.StoreMembershipCredential(ApplicationId, data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task SendMail_ReturnsExpectedCount()
var mailData = _fixture.Create<MailData>();

//Act
var result = await _controller.SendMail(mailData).ConfigureAwait(false);
var result = await _controller.SendMail(mailData);

//Assert
A.CallTo(() => _logic.SendMail(mailData)).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.Tests</RootNamespace>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.IssuerComponentIssuerComponent.Library.Tests</AssemblyName>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture.AutoFakeItEasy" Version="4.18.0" />
<PackageReference Include="FakeItEasy" Version="7.4.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="AutoFixture.AutoFakeItEasy" Version="4.18.1" />
<PackageReference Include="FakeItEasy" Version="8.1.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task CreateBpnlCredential_WithValid_CallsExpected()
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "did:123:testabc", ValidBpn, new WalletInformation("cl1", secret, vector, 0, "https://example.com/wallet")));

// Act
var result = await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
var result = await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Assert
A.CallTo(() => _issuerComponentService.CreateBpnlCredential(A<CreateBpnCredentialRequest>._, A<CancellationToken>._))
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task CreateBpnlCredential_WithApplicationNotFound_ThrowsNotFoundExc
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(false, null, null, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<NotFoundException>(Act);
Expand All @@ -166,7 +166,7 @@ public async Task CreateBpnlCredential_WithHolderNotSet_ThrowsConflictException(
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, null, null, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand All @@ -192,7 +192,7 @@ public async Task CreateBpnlCredential_WithBpnNotSet_ThrowsConflictException()
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "test123", null, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand All @@ -218,7 +218,7 @@ public async Task CreateBpnlCredential_WithWalletInformationNotSet_ThrowsConflic
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "test123", ValidBpn, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand Down Expand Up @@ -250,7 +250,7 @@ public async Task StoreBpnlCredential_WithSuccessful_UpdatesEntry()
SetupForProcessIssuerComponentResponse(entry);

// Act
await _sut.StoreBpnlCredential(IdWithBpn, data).ConfigureAwait(false);
await _sut.StoreBpnlCredential(IdWithBpn, data);

// Assert
A.CallTo(() => _checklistService.FinalizeChecklistEntryAndProcessSteps(A<IApplicationChecklistService.ManualChecklistProcessStepData>._, A<Action<ApplicationChecklistEntry>>._, A<Action<ApplicationChecklistEntry>>._, A<IEnumerable<ProcessStepTypeId>>.That.Matches(x => x.Count(y => y == ProcessStepTypeId.REQUEST_MEMBERSHIP_CREDENTIAL) == 1))).MustHaveHappenedOnceExactly();
Expand All @@ -276,7 +276,7 @@ public async Task StoreBpnlCredential_WithUnsuccessful_UpdatesEntry()
SetupForProcessIssuerComponentResponse(entry);

// Act
await _sut.StoreBpnlCredential(IdWithBpn, data).ConfigureAwait(false);
await _sut.StoreBpnlCredential(IdWithBpn, data);

// Assert
A.CallTo(() => _checklistService.FinalizeChecklistEntryAndProcessSteps(A<IApplicationChecklistService.ManualChecklistProcessStepData>._, A<Action<ApplicationChecklistEntry>>._, A<Action<ApplicationChecklistEntry>>._, A<IEnumerable<ProcessStepTypeId>>.That.IsNull())).MustHaveHappenedOnceExactly();
Expand Down Expand Up @@ -309,7 +309,7 @@ public async Task CreateMembershipCredential_WithValid_CallsExpected()
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "did:123:testabc", ValidBpn, new WalletInformation("cl1", secret, vector, 0, "https://example.com/wallet")));

// Act
var result = await _sut.CreateMembershipCredential(context, CancellationToken.None).ConfigureAwait(false);
var result = await _sut.CreateMembershipCredential(context, CancellationToken.None);

// Assert
A.CallTo(() => _issuerComponentService.CreateMembershipCredential(A<CreateMembershipCredentialRequest>._, A<CancellationToken>._))
Expand Down Expand Up @@ -338,7 +338,7 @@ public async Task CreateMembershipCredential_WithApplicationNotFound_ThrowsNotFo
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(false, null, null, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<NotFoundException>(Act);
Expand All @@ -364,7 +364,7 @@ public async Task CreateMembershipCredential_WithHolderNotSet_ThrowsConflictExce
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, null, null, null));
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateBpnlCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand All @@ -390,7 +390,7 @@ public async Task CreateMembershipCredential_WithBpnNotSet_ThrowsConflictExcepti
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "test123", null, null));
async Task Act() => await _sut.CreateMembershipCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateMembershipCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand All @@ -416,7 +416,7 @@ public async Task CreateMembershipCredential_WithWalletInformationNotSet_ThrowsC
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithBpn, ProcessStepTypeId.REQUEST_BPN_CREDENTIAL, checklist, Enumerable.Empty<ProcessStepTypeId>());
A.CallTo(() => _applicationRepository.GetBpnlCredentialIformationByApplicationId(IdWithBpn))
.Returns(new ValueTuple<bool, string?, string?, WalletInformation?>(true, "test123", ValidBpn, null));
async Task Act() => await _sut.CreateMembershipCredential(context, CancellationToken.None).ConfigureAwait(false);
async Task Act() => await _sut.CreateMembershipCredential(context, CancellationToken.None);

// Act
var ex = await Assert.ThrowsAsync<ConflictException>(Act);
Expand Down Expand Up @@ -448,7 +448,7 @@ public async Task StoreMembershipCredential_WithSuccessful_UpdatesEntry()
SetupForProcessIssuerComponentResponse(entry);

// Act
await _sut.StoreMembershipCredential(IdWithBpn, data).ConfigureAwait(false);
await _sut.StoreMembershipCredential(IdWithBpn, data);

// Assert
A.CallTo(() => _checklistService.FinalizeChecklistEntryAndProcessSteps(A<IApplicationChecklistService.ManualChecklistProcessStepData>._, A<Action<ApplicationChecklistEntry>>._, A<Action<ApplicationChecklistEntry>>._, A<IEnumerable<ProcessStepTypeId>>.That.Matches(x => x.Count(y => y == ProcessStepTypeId.START_CLEARING_HOUSE) == 1))).MustHaveHappenedOnceExactly();
Expand All @@ -474,7 +474,7 @@ public async Task StoreMembershipCredential_WithUnsuccessful_UpdatesEntry()
SetupForProcessIssuerComponentResponse(entry);

// Act
await _sut.StoreMembershipCredential(IdWithBpn, data).ConfigureAwait(false);
await _sut.StoreMembershipCredential(IdWithBpn, data);

// Assert
A.CallTo(() => _checklistService.FinalizeChecklistEntryAndProcessSteps(A<IApplicationChecklistService.ManualChecklistProcessStepData>._, A<Action<ApplicationChecklistEntry>>._, A<Action<ApplicationChecklistEntry>>._, A<IEnumerable<ProcessStepTypeId>>.That.IsNull())).MustHaveHappenedOnceExactly();
Expand Down
Loading

0 comments on commit ec1fd9b

Please sign in to comment.