Skip to content

Commit

Permalink
106 create certification bug (#108)
Browse files Browse the repository at this point in the history
* fix empty photo bug

* remove using
  • Loading branch information
decembrya authored Oct 5, 2021
1 parent 9163c82 commit 69ef191
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
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();
}
}
}

0 comments on commit 69ef191

Please sign in to comment.