Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

106 create certification bug #108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ public async Task<Result<CertificationModel>> Handle(CreateCertification request
await _context.Certifications.AddAsync(certification, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);

var photoUrl = await _storage.SaveAttachmentAsync(certification.Id,
user.Sub,
request.Photo.OpenReadStream(),
Path.GetExtension(request.Photo.FileName));
string photoUrl = null;
if (request.Photo != null)
{
photoUrl = await _storage.SaveAttachmentAsync(certification.Id,
user.Sub,
request.Photo.OpenReadStream(),
Path.GetExtension(request.Photo.FileName));
}

return new CertificationModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using DeUrgenta.Certifications.Api.Commands;
using DeUrgenta.Certifications.Api.Models;
using DeUrgenta.Certifications.Api.Storage;
using DeUrgenta.Certifications.Api.Tests.Builders;
using DeUrgenta.Common.Validation;
using DeUrgenta.Domain;
using DeUrgenta.Domain.Entities;
using DeUrgenta.Tests.Helpers;
using NSubstitute;
using Shouldly;
Expand Down Expand Up @@ -41,5 +43,40 @@ public async Task Return_failed_result_when_validation_fails()
// Assert
result.IsFailure.ShouldBeTrue();
}

[Fact]
public async Task Return_success_if_photo_is_not_provided_in_request()
{
//Arrange
var userSub = TestDataProviders.RandomString();
var certificationRequest = new CertificationRequestBuilder()
.WithPhoto(null)
.Build();

var user = new User
{
Sub = userSub,
FirstName = TestDataProviders.RandomString(),
LastName = TestDataProviders.RandomString()
};
await _dbContext.Users.AddAsync(user);
await _dbContext.SaveChangesAsync();

var createCertification = new CreateCertification(userSub, certificationRequest);

var storage = Substitute.For<IBlobStorage>();
var validator = Substitute.For<IValidateRequest<CreateCertification>>();
validator
.IsValidAsync(createCertification)
.Returns(Task.FromResult(true));

var sut = new CreateCertificationHandler(validator, _dbContext, storage);

//Act
var result = await sut.Handle(createCertification, CancellationToken.None);

//Assert
result.IsSuccess.ShouldBeTrue();
}
}
}