Skip to content

Commit

Permalink
fix+test(quetzalcoatl): remove obsolete tests and add new type format…
Browse files Browse the repository at this point in the history
…ters for response parsing
  • Loading branch information
WarriorsSami committed Jun 19, 2024
1 parent a5abdfd commit 3dfaabc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Net.Http.Formatting;

namespace Tests.Integration.Api.Features.Auth;

public class RegisterEndpointTests : IClassFixture<ApiWebFactory>
Expand Down Expand Up @@ -144,11 +146,17 @@ public async Task GivenInvalidUser_WhenRegistering_ThenReturnsBadRequest()
// check if AccessToken and RefreshToken cookies exist
response.Headers.TryGetValues("Set-Cookie", out _).Should().BeFalse();

var result = await response.Content.ReadAsAsync<ErrorResponse>();
var formatters = new MediaTypeFormatterCollection();
formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/problem+json"));

var result = await response.Content.ReadAsAsync<ErrorResponse>(formatters: formatters);

result.Should().NotBeNull();
result!.Errors.Keys.Should().Contain(nameof(request.Password));
result.Errors.Keys.Should().Contain(nameof(request.ProfilePicture));
result!.Errors.Keys.Select(r => r.ToUpper())
.Should().Contain(nameof(request.Password).ToUpper());
result.Errors.Keys.Select(r => r.ToUpper())
.Should().Contain(nameof(request.ProfilePicture).ToUpper());

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,6 @@ public GetImageEndpointTests(ApiWebFactory apiWebFactory)

#endregion

[Fact]
public async Task GivenAnonymousUser_WhenGettingImage_ThenReturnsUnauthorized()
{
#region Arrange

using var scope = _apiWebFactory.Services.CreateScope();
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();

var profilePictureData = await ImageHelpers.GetImageAsByteArrayAsync(
"https://picsum.photos/200"
);
var profilePicture = new Picture { Data = profilePictureData };

var applicationUser = _applicationUserFaker
.Clone()
.RuleFor(rule => rule.ProfilePicture, profilePicture)
.Generate();

const string validPassword = "P@ssw0rd!";
await userManager.CreateAsync(applicationUser, validPassword);

var request = new GetImageRequest { Id = applicationUser.ProfilePicture!.Id };

#endregion

#region Act

var response = await _client.GETAsync<GetImageEndpoint, GetImageRequest>(request);

#endregion

#region Assert

response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);

#endregion
}

[Fact]
public async Task GivenAuthorizedUserAndNonExistingImageId_WhenGettingImage_ThenReturnsNotFound()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task GivenAnonymousUser_WhenDeletingUser_ThenReturnsUnauthorized()

const string validPassword = "P@ssw0rd!";
await userManager.CreateAsync(applicationUser, validPassword);
var users = await userManager.Users.ToListAsync();

var request = new DeleteUserRequest { Id = applicationUser.Id };

Expand Down

0 comments on commit 3dfaabc

Please sign in to comment.