Skip to content

Commit

Permalink
cover more conditions for signing receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
HauklandJ committed Feb 25, 2025
1 parent 4760ed7 commit cf3324c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task SendSignCallToAction_SmsNotificationConfigured_CallsCorrespond
InstanceIdentifier instanceIdentifier = new(123, Guid.Parse("ab0cdeb5-dc5e-4faa-966b-d18bb932ca07"));
Party signingParty = new() { Name = "Signee", SSN = "17858296439" };
Party serviceOwnerParty = new() { Name = "Service owner", OrgNumber = "043871668" };
List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_appname" },
];
Expand All @@ -136,7 +136,7 @@ await service.SendSignCallToAction(
instanceIdentifier,
signingParty,
serviceOwnerParty,
CorrespondenceResources
correspondenceResources
);

// Assert
Expand Down Expand Up @@ -211,7 +211,7 @@ public async Task SendSignCallToAction_EmailNotificationConfigured_CallsCorrespo
InstanceIdentifier instanceIdentifier = new(123, Guid.Parse("ab0cdeb5-dc5e-4faa-966b-d18bb932ca07"));
Party signingParty = new() { Name = "Signee", SSN = "17858296439" };
Party serviceOwnerParty = new() { Name = "Service owner", OrgNumber = "043871668" };
List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_appname" },
];
Expand All @@ -223,7 +223,7 @@ await service.SendSignCallToAction(
instanceIdentifier,
signingParty,
serviceOwnerParty,
CorrespondenceResources
correspondenceResources
);

// Assert
Expand Down Expand Up @@ -301,7 +301,7 @@ public async Task SendSignCallToAction_SmsAndEmailNotificationConfigured_CallsCo
InstanceIdentifier instanceIdentifier = new(123, Guid.Parse("ab0cdeb5-dc5e-4faa-966b-d18bb932ca07"));
Party signingParty = new() { Name = "Signee", SSN = "17858296439" };
Party serviceOwnerParty = new() { Name = "Service owner", OrgNumber = "043871668" };
List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_appname" },
];
Expand All @@ -313,7 +313,7 @@ await service.SendSignCallToAction(
instanceIdentifier,
signingParty,
serviceOwnerParty,
CorrespondenceResources
correspondenceResources
);

// Assert
Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task SendSignCallToAction_NotificationNotConfigured_CallsCorrespond
InstanceIdentifier instanceIdentifier = new(123, Guid.Parse("ab0cdeb5-dc5e-4faa-966b-d18bb932ca07"));
Party signingParty = new() { Name = "Signee", SSN = "17858296439" };
Party serviceOwnerParty = new() { Name = "Service owner", OrgNumber = "043871668" };
List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_appname" },
];
Expand All @@ -387,7 +387,7 @@ await service.SendSignCallToAction(
instanceIdentifier,
signingParty,
serviceOwnerParty,
CorrespondenceResources
correspondenceResources
);

// Assert
Expand Down Expand Up @@ -455,7 +455,7 @@ public async Task SendSignCallToAction_ResourceNotFound_ThrowsException()
InstanceIdentifier instanceIdentifier = new(123, Guid.Parse("ab0cdeb5-dc5e-4faa-966b-d18bb932ca07"));
Party signingParty = new() { Name = "Signee", SSN = "17858296439" };
Party serviceOwnerParty = new() { Name = "Service owner", OrgNumber = "043871668" };
List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
// No resource for tt02 - should throw exception
];
Expand All @@ -469,7 +469,7 @@ await service.SendSignCallToAction(
instanceIdentifier,
signingParty,
serviceOwnerParty,
CorrespondenceResources
correspondenceResources
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Altinn.App.Core.Exceptions;
using Altinn.App.Core.Features;
using Altinn.App.Core.Features.Correspondence;
using Altinn.App.Core.Features.Correspondence.Models;
Expand All @@ -11,20 +12,16 @@
using Altinn.App.Core.Internal.Sign;
using Altinn.App.Core.Models;
using Altinn.App.Core.Models.UserAction;
using Altinn.Platform.Register.Enums;
using Altinn.Platform.Register.Models;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Moq;
using static Altinn.App.Core.Features.Signing.Models.Signee;
using Signee = Altinn.App.Core.Features.Signing.Models.Signee;

namespace Altinn.App.Core.Tests.Features.Signing;

public class SigningReceiptServiceTests
{
SigningReceiptService SetupService(
static SigningReceiptService SetupService(
Mock<ICorrespondenceClient>? correspondenceClientMockOverride = null,
Mock<IHostEnvironment>? hostEnvironmentMockOverride = null,
Mock<IDataClient>? dataClientMockOverride = null,
Expand Down Expand Up @@ -139,7 +136,7 @@ public async Task SendSignatureReceipt_CallsCorrespondenceClientWithCorrectParam
new DataElementSignature("11111111-1111-1111-1111-111111111111"),
];

List<AltinnEnvironmentConfig> CorrespondenceResources =
List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_receipt" },
];
Expand All @@ -150,7 +147,7 @@ await service.SendSignatureReceipt(
signee,
dataElementSignatures,
context,
CorrespondenceResources
correspondenceResources
);

// Assert
Expand All @@ -176,6 +173,62 @@ capturedPayload.CorrespondenceRequest.Recipients[0] as OrganisationOrPersonIdent
);
}

[Fact]
public async Task GetCorrespondenceHeaders_NoResource_ThrowsConfigurationException()
{
// Arrange
ApplicationMetadata applicationMetadata = new("org/app")
{
Title = new Dictionary<string, string> { { LanguageConst.Nb, "TestAppName" } },
Org = "brg",
};

Mock<IHostEnvironment> hostEnvironmentMock = new();
hostEnvironmentMock.Setup(m => m.EnvironmentName).Returns("tt02");

SigningReceiptService service = SetupService(hostEnvironmentMockOverride: hostEnvironmentMock);

var recipientNin = "11854995997";

List<AltinnEnvironmentConfig> correspondenceResources =
[
// No resource configured for the environment
];

// Act & Assert
await Assert.ThrowsAsync<ConfigurationException>(
() => service.GetCorrespondenceHeaders(recipientNin, applicationMetadata, correspondenceResources)
);
}

[Fact]
public async Task GetCorrespondenceHeaders_RecipientNinIsNull_ThrowsInvalidOperationException()
{
// Arrange
ApplicationMetadata applicationMetadata = new("org/app")
{
Title = new Dictionary<string, string> { { LanguageConst.Nb, "TestAppName" } },
Org = "brg",
};

Mock<IHostEnvironment> hostEnvironmentMock = new();
hostEnvironmentMock.Setup(m => m.EnvironmentName).Returns("tt02");

SigningReceiptService service = SetupService(hostEnvironmentMockOverride: hostEnvironmentMock);

string? recipientNin = null;

List<AltinnEnvironmentConfig> correspondenceResources =
[
new AltinnEnvironmentConfig { Environment = "tt02", Value = "app_ttd_receipt" },
];

// Act & Assert
await Assert.ThrowsAsync<InvalidOperationException>(
() => service.GetCorrespondenceHeaders(recipientNin, applicationMetadata, correspondenceResources)
);
}

[Fact]
public async Task GetContent_WithCustomTexts_ReturnsCustomContent()
{
Expand Down

0 comments on commit cf3324c

Please sign in to comment.