From 3dfaabcb57a20837508d058a486f4bb300b0a7c4 Mon Sep 17 00:00:00 2001 From: WarriorsSami Date: Wed, 19 Jun 2024 23:31:36 +0300 Subject: [PATCH] fix+test(quetzalcoatl): remove obsolete tests and add new type formatters for response parsing --- .../Features/Auth/RegisterEndpointTests.cs | 14 +++++-- .../Features/Images/GetImageEndpointTests.cs | 39 ------------------- .../Api/Features/Users/DeleteEndpointTests.cs | 1 + 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/quetzalcoatl-auth/Tests.Integration/Api/Features/Auth/RegisterEndpointTests.cs b/quetzalcoatl-auth/Tests.Integration/Api/Features/Auth/RegisterEndpointTests.cs index 656c93f..71cad99 100644 --- a/quetzalcoatl-auth/Tests.Integration/Api/Features/Auth/RegisterEndpointTests.cs +++ b/quetzalcoatl-auth/Tests.Integration/Api/Features/Auth/RegisterEndpointTests.cs @@ -1,3 +1,5 @@ +using System.Net.Http.Formatting; + namespace Tests.Integration.Api.Features.Auth; public class RegisterEndpointTests : IClassFixture @@ -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(); + 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(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 } diff --git a/quetzalcoatl-auth/Tests.Integration/Api/Features/Images/GetImageEndpointTests.cs b/quetzalcoatl-auth/Tests.Integration/Api/Features/Images/GetImageEndpointTests.cs index 480ac9f..337737d 100644 --- a/quetzalcoatl-auth/Tests.Integration/Api/Features/Images/GetImageEndpointTests.cs +++ b/quetzalcoatl-auth/Tests.Integration/Api/Features/Images/GetImageEndpointTests.cs @@ -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>(); - - 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(request); - - #endregion - - #region Assert - - response.Should().NotBeNull(); - response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); - - #endregion - } - [Fact] public async Task GivenAuthorizedUserAndNonExistingImageId_WhenGettingImage_ThenReturnsNotFound() { diff --git a/quetzalcoatl-auth/Tests.Integration/Api/Features/Users/DeleteEndpointTests.cs b/quetzalcoatl-auth/Tests.Integration/Api/Features/Users/DeleteEndpointTests.cs index d4e76b5..75d1598 100644 --- a/quetzalcoatl-auth/Tests.Integration/Api/Features/Users/DeleteEndpointTests.cs +++ b/quetzalcoatl-auth/Tests.Integration/Api/Features/Users/DeleteEndpointTests.cs @@ -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 };