Added `IAuthenticator` dependency to `CreateEnvelopeCommandHandler` to enable access code generation for envelope receivers. Updated the `AccessCode` property of `EnvelopeReceiver` to store a 5-character code generated by `Authenticator.GenerateCode`. Introduced a new test class `CreateEnvelopeCommandTests` with a test method `CreateEnvelope_ShouldGenerateAccessCode_ForEnvelopeReceiver` to validate the functionality. The test ensures that the access code is generated, not null, not empty, and has the correct length. Updated test setup to include necessary configurations and dependencies.
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using EnvelopeGenerator.Application.Envelopes.Commands;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace EnvelopeGenerator.Tests.Application;
|
|
|
|
public class CreateEnvelopeCommandTests : TestBase
|
|
{
|
|
protected override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
}
|
|
|
|
[Test]
|
|
public async Task CreateEnvelope_ShouldGenerateAccessCode_ForEnvelopeReceiver()
|
|
{
|
|
var command = new CreateEnvelopeCommand
|
|
{
|
|
Title = "Test Envelope",
|
|
Message = "Test Message",
|
|
UseSQLExecutor = false,
|
|
Document = new CreateEnvelopeDocumentDto(this.CreatePdfAsBase64()),
|
|
Receivers =
|
|
[
|
|
new CreateEnvelopeReceiverDto(
|
|
EmailAddress: this.Internet.Email(),
|
|
Name: this.Name.FullName(),
|
|
PhoneNumber: null,
|
|
Fields: [new CreateEnvelopeFieldDto(X: 1.0, Y: 1.0, Page: 1)])
|
|
]
|
|
}.WithAuth(User.Id);
|
|
|
|
var result = await Mediator.Send(command);
|
|
|
|
Assert.That(result, Is.Not.Null);
|
|
|
|
var receiverRepository = GetRepository<EnvelopeReceiver>();
|
|
var envelopeReceiver = receiverRepository.Query
|
|
.FirstOrDefault(x => x.EnvelopeId == result!.Id);
|
|
|
|
Assert.That(envelopeReceiver, Is.Not.Null);
|
|
Assert.That(envelopeReceiver!.AccessCode, Is.Not.Null.And.Not.Empty);
|
|
Assert.That(envelopeReceiver.AccessCode.Length, Is.EqualTo(5));
|
|
}
|
|
}
|