diff --git a/src/TeamUp.Api/Endpoints/Invitations/AcceptInvitaionEndpoint.cs b/src/TeamUp.Api/Endpoints/Invitations/AcceptInvitaionEndpoint.cs index 3472206..1cab3a1 100644 --- a/src/TeamUp.Api/Endpoints/Invitations/AcceptInvitaionEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Invitations/AcceptInvitaionEndpoint.cs @@ -18,8 +18,8 @@ public void MapEndpoints(RouteGroupBuilder group) .ProducesProblem(StatusCodes.Status401Unauthorized) .ProducesProblem(StatusCodes.Status403Forbidden) .ProducesProblem(StatusCodes.Status404NotFound) - .MapToApiVersion(1) - .WithName(nameof(AcceptInvitationEndpoint)); + .WithName(nameof(AcceptInvitationEndpoint)) + .MapToApiVersion(1); } private async Task AcceptInvitationAsync( @@ -28,7 +28,7 @@ private async Task AcceptInvitationAsync( [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) { - var command = new AcceptInvitationCommand(httpContextAccessor.GetLoggedUserId(), InvitationId.FromGuid(invitationId)); + var command = new AcceptInvitationCommand(httpContextAccessor.GetCurrentUserId(), InvitationId.FromGuid(invitationId)); var result = await sender.Send(command, ct); return result.Match(TypedResults.Ok); } diff --git a/src/TeamUp.Api/Endpoints/Invitations/GetTeamInvitationsEndpoint.cs b/src/TeamUp.Api/Endpoints/Invitations/GetTeamInvitationsEndpoint.cs index c269dfd..eba4a52 100644 --- a/src/TeamUp.Api/Endpoints/Invitations/GetTeamInvitationsEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Invitations/GetTeamInvitationsEndpoint.cs @@ -28,7 +28,7 @@ private async Task GetTeamInvitationsAsync( [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) { - var query = new GetTeamInvitationsQuery(httpContextAccessor.GetLoggedUserId(), TeamId.FromGuid(teamId)); + var query = new GetTeamInvitationsQuery(httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId)); var result = await sender.Send(query, ct); return result.Match(TypedResults.Ok); } diff --git a/src/TeamUp.Api/Endpoints/Invitations/InviteUserEndpoint.cs b/src/TeamUp.Api/Endpoints/Invitations/InviteUserEndpoint.cs index 96c51e5..68cd697 100644 --- a/src/TeamUp.Api/Endpoints/Invitations/InviteUserEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Invitations/InviteUserEndpoint.cs @@ -14,12 +14,12 @@ public void MapEndpoints(RouteGroupBuilder group) { group.MapPost("/", InviteUserAsync) .Produces(StatusCodes.Status201Created) - .Produces(StatusCodes.Status401Unauthorized) - .Produces(StatusCodes.Status403Forbidden) - .Produces(StatusCodes.Status404NotFound) + .ProducesProblem(StatusCodes.Status401Unauthorized) + .ProducesProblem(StatusCodes.Status403Forbidden) + .ProducesProblem(StatusCodes.Status404NotFound) .ProducesValidationProblem() - .MapToApiVersion(1) - .WithName(nameof(InviteUserEndpoint)); + .WithName(nameof(InviteUserEndpoint)) + .MapToApiVersion(1); } private async Task InviteUserAsync( @@ -29,7 +29,7 @@ private async Task InviteUserAsync( [FromServices] LinkGenerator linkGenerator, CancellationToken ct) { - var command = new InviteUserCommand(httpContextAccessor.GetLoggedUserId(), request.TeamId, request.Email); + var command = new InviteUserCommand(httpContextAccessor.GetCurrentUserId(), request.TeamId, request.Email); var result = await sender.Send(command, ct); return result.Match(invitationId => TypedResults.Created( diff --git a/src/TeamUp.Api/Endpoints/Teams/ChangeNicknameEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/ChangeNicknameEndpoint.cs index ce7246a..1ef2702 100644 --- a/src/TeamUp.Api/Endpoints/Teams/ChangeNicknameEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/ChangeNicknameEndpoint.cs @@ -30,7 +30,7 @@ private async Task ChangeNicknameAsync( CancellationToken ct) { var command = new ChangeNicknameCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), request.Nickname ); diff --git a/src/TeamUp.Api/Endpoints/Teams/ChangeOwnerShipEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/ChangeOwnerShipEndpoint.cs index 3e19ac0..02b7f8a 100644 --- a/src/TeamUp.Api/Endpoints/Teams/ChangeOwnerShipEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/ChangeOwnerShipEndpoint.cs @@ -29,7 +29,7 @@ private async Task ChangeOwnerShipAsync( CancellationToken ct) { var command = new ChangeOwnershipCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), TeamMemberId.FromGuid(teamMemberId) ); diff --git a/src/TeamUp.Api/Endpoints/Teams/CreateEventTypeEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/CreateEventTypeEndpoint.cs index f61ecd9..568e47b 100644 --- a/src/TeamUp.Api/Endpoints/Teams/CreateEventTypeEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/CreateEventTypeEndpoint.cs @@ -14,9 +14,9 @@ public void MapEndpoints(RouteGroupBuilder group) { group.MapPost("/{teamId:guid}/event-types", CreateEventTypeAsync) .Produces(StatusCodes.Status201Created) - .Produces(StatusCodes.Status401Unauthorized) - .Produces(StatusCodes.Status403Forbidden) - .Produces(StatusCodes.Status404NotFound) + .ProducesProblem(StatusCodes.Status401Unauthorized) + .ProducesProblem(StatusCodes.Status403Forbidden) + .ProducesProblem(StatusCodes.Status404NotFound) .ProducesValidationProblem() .WithName(nameof(CreateEventTypeEndpoint)) .MapToApiVersion(1); @@ -31,7 +31,7 @@ private async Task CreateEventTypeAsync( CancellationToken ct) { var command = new CreateEventTypeCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), request.Name, request.Description diff --git a/src/TeamUp.Api/Endpoints/Teams/CreateTeamEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/CreateTeamEndpoint.cs index 36b5987..8c31fa9 100644 --- a/src/TeamUp.Api/Endpoints/Teams/CreateTeamEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/CreateTeamEndpoint.cs @@ -26,7 +26,7 @@ private async Task CreateTeamAsync( [FromServices] LinkGenerator linkGenerator, CancellationToken ct) { - var command = new CreateTeamCommand(httpContextAccessor.GetLoggedUserId(), request.Name); + var command = new CreateTeamCommand(httpContextAccessor.GetCurrentUserId(), request.Name); var result = await sender.Send(command, ct); return result.Match(teamId => TypedResults.Created( uri: linkGenerator.GetPathByName(nameof(GetTeamEndpoint), teamId.Value), diff --git a/src/TeamUp.Api/Endpoints/Teams/DeleteTeamEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/DeleteTeamEndpoint.cs index b1ddc9d..5f9eb65 100644 --- a/src/TeamUp.Api/Endpoints/Teams/DeleteTeamEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/DeleteTeamEndpoint.cs @@ -27,7 +27,7 @@ private async Task DeleteTeamAsync( [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) { - var command = new DeleteTeamCommand(httpContextAccessor.GetLoggedUserId(), TeamId.FromGuid(teamId)); + var command = new DeleteTeamCommand(httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId)); var result = await sender.Send(command, ct); return result.Match(TypedResults.Ok); } diff --git a/src/TeamUp.Api/Endpoints/Teams/GetTeamEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/GetTeamEndpoint.cs index 4c27f6c..a3ae5a3 100644 --- a/src/TeamUp.Api/Endpoints/Teams/GetTeamEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/GetTeamEndpoint.cs @@ -27,7 +27,7 @@ private async Task GetTeamAsync( [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) { - var query = new GetTeamQuery(httpContextAccessor.GetLoggedUserId(), TeamId.FromGuid(teamId)); + var query = new GetTeamQuery(httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId)); var result = await sender.Send(query, ct); return result.Match(TypedResults.Ok); } diff --git a/src/TeamUp.Api/Endpoints/Teams/RemoveTeamMemberEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/RemoveTeamMemberEndpoint.cs index c824d97..2fe7df5 100644 --- a/src/TeamUp.Api/Endpoints/Teams/RemoveTeamMemberEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/RemoveTeamMemberEndpoint.cs @@ -12,7 +12,7 @@ public sealed class RemoveTeamMemberEndpoint : IEndpointGroup { public void MapEndpoints(RouteGroupBuilder group) { - group.MapDelete("/{teamId:guid}/{teamMemberId:guid}", RemoveTeamMemberAsync) + group.MapDelete("/{teamId:guid}/members/{teamMemberId:guid}", RemoveTeamMemberAsync) .Produces(StatusCodes.Status200OK) .ProducesProblem(StatusCodes.Status400BadRequest) .ProducesProblem(StatusCodes.Status401Unauthorized) @@ -30,7 +30,7 @@ private async Task RemoveTeamMemberAsync( CancellationToken ct) { var command = new RemoveTeamMemberCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), TeamMemberId.FromGuid(teamMemberId) ); diff --git a/src/TeamUp.Api/Endpoints/Teams/UpdateTeamMemberRoleEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/UpdateTeamMemberRoleEndpoint.cs index 1d82bc3..cf455ec 100644 --- a/src/TeamUp.Api/Endpoints/Teams/UpdateTeamMemberRoleEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/UpdateTeamMemberRoleEndpoint.cs @@ -12,7 +12,7 @@ public sealed class UpdateTeamMemberRoleEndpoint : IEndpointGroup { public void MapEndpoints(RouteGroupBuilder group) { - group.MapPut("/{teamId:guid}/{teamMemberId:guid}/role", UpdateTeamRoleAsync) + group.MapPut("/{teamId:guid}/members/{teamMemberId:guid}/role", UpdateTeamRoleAsync) .Produces(StatusCodes.Status200OK) .ProducesProblem(StatusCodes.Status400BadRequest) .ProducesProblem(StatusCodes.Status401Unauthorized) @@ -32,7 +32,7 @@ private async Task UpdateTeamRoleAsync( CancellationToken ct) { var command = new SetMemberRoleCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), TeamMemberId.FromGuid(teamMemberId), request.Role diff --git a/src/TeamUp.Api/Endpoints/Teams/UpdateTeamNameEndpoint.cs b/src/TeamUp.Api/Endpoints/Teams/UpdateTeamNameEndpoint.cs index 9512b52..7ff4c70 100644 --- a/src/TeamUp.Api/Endpoints/Teams/UpdateTeamNameEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/Teams/UpdateTeamNameEndpoint.cs @@ -30,7 +30,7 @@ private async Task UpdateTeamNameAsync( CancellationToken ct) { var command = new SetTeamNameCommand( - httpContextAccessor.GetLoggedUserId(), + httpContextAccessor.GetCurrentUserId(), TeamId.FromGuid(teamId), request.Name ); diff --git a/src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs b/src/TeamUp.Api/Endpoints/UserAccess/GetMyAccountDetailsEndpoint.cs similarity index 57% rename from src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs rename to src/TeamUp.Api/Endpoints/UserAccess/GetMyAccountDetailsEndpoint.cs index 0d1cd26..de2a8e8 100644 --- a/src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/UserAccess/GetMyAccountDetailsEndpoint.cs @@ -3,29 +3,29 @@ using Microsoft.AspNetCore.Mvc; using TeamUp.Api.Extensions; -using TeamUp.Application.Users.GetUserDetail; +using TeamUp.Application.Users.GetAccountDetails; using TeamUp.Contracts.Users; namespace TeamUp.Api.Endpoints.UserAccess; -public sealed class GetUserDetailsEndpoint : IEndpointGroup +public sealed class GetMyAccountDetailsEndpoint : IEndpointGroup { public void MapEndpoints(RouteGroupBuilder group) { - group.MapGet("/", GetUserDetailsAsync) - .Produces(StatusCodes.Status200OK) + group.MapGet("/", GetAccountDetailsAsync) + .Produces(StatusCodes.Status200OK) .ProducesProblem(StatusCodes.Status401Unauthorized) - .WithName(nameof(GetUserDetailsEndpoint)) + .WithName(nameof(GetMyAccountDetailsEndpoint)) .MapToApiVersion(1) .RequireAuthorization(); } - private async Task GetUserDetailsAsync( + private async Task GetAccountDetailsAsync( [FromServices] ISender sender, [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) { - var query = new GetUserDetailsQuery(httpContextAccessor.GetLoggedUserId()); + var query = new GetAccountDetailsQuery(httpContextAccessor.GetCurrentUserId()); var result = await sender.Send(query, ct); return result.Match(TypedResults.Ok); } diff --git a/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs b/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs index a1bbae0..f2dff3d 100644 --- a/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs @@ -14,6 +14,7 @@ public void MapEndpoints(RouteGroupBuilder group) { group.MapPost("/register", RegisterUserAsync) .Produces(StatusCodes.Status201Created) + .ProducesProblem(StatusCodes.Status409Conflict) .ProducesValidationProblem() .WithName(nameof(RegisterUserEndpoint)) .MapToApiVersion(1); @@ -29,7 +30,7 @@ private async Task RegisterUserAsync( var command = mapper.ToCommand(request); var result = await sender.Send(command, ct); return result.Match( - userId => TypedResults.Created(linkGenerator.GetPathByName(nameof(GetUserDetailsEndpoint)), userId) + userId => TypedResults.Created(linkGenerator.GetPathByName(nameof(GetMyAccountDetailsEndpoint)), userId) ); } } diff --git a/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs b/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs index 435b118..97c964f 100644 --- a/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs +++ b/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs @@ -10,6 +10,6 @@ public void MapEndpoints(RouteGroupBuilder group) group.MapEndpoint() .MapEndpoint() .MapEndpoint() - .MapEndpoint(); + .MapEndpoint(); } } diff --git a/src/TeamUp.Api/Extensions/HttpContextExtensions.cs b/src/TeamUp.Api/Extensions/HttpContextExtensions.cs index d0332ad..88a185b 100644 --- a/src/TeamUp.Api/Extensions/HttpContextExtensions.cs +++ b/src/TeamUp.Api/Extensions/HttpContextExtensions.cs @@ -7,7 +7,7 @@ namespace TeamUp.Api.Extensions; public static class HttpContextExtensions { - public static UserId GetLoggedUserId(this IHttpContextAccessor contextAccessor) => + public static UserId GetCurrentUserId(this IHttpContextAccessor contextAccessor) => UserId.FromGuid(contextAccessor.ParseClaim(ClaimTypes.NameIdentifier, Guid.Parse)); public static TOut ParseClaim(this IHttpContextAccessor contextAccessor, string type, Func parse) diff --git a/src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQuery.cs b/src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQuery.cs new file mode 100644 index 0000000..685a95b --- /dev/null +++ b/src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQuery.cs @@ -0,0 +1,7 @@ +using TeamUp.Application.Abstractions; +using TeamUp.Common; +using TeamUp.Contracts.Users; + +namespace TeamUp.Application.Users.GetAccountDetails; + +public sealed record GetAccountDetailsQuery(UserId UserId) : IQuery>; diff --git a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs b/src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQueryHandler.cs similarity index 57% rename from src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs rename to src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQueryHandler.cs index 89342a3..c4d60b7 100644 --- a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs +++ b/src/TeamUp.Application/Users/GetAccountDetails/GetAccountDetailsQueryHandler.cs @@ -5,22 +5,22 @@ using TeamUp.Contracts.Users; using TeamUp.Domain.Aggregates.Users; -namespace TeamUp.Application.Users.GetUserDetail; +namespace TeamUp.Application.Users.GetAccountDetails; -internal sealed class GetUserDetailsQueryHandler : IQueryHandler> +internal sealed class GetAccountDetailsQueryHandler : IQueryHandler> { private readonly IAppQueryContext _queryContext; - public GetUserDetailsQueryHandler(IAppQueryContext queryContext) + public GetAccountDetailsQueryHandler(IAppQueryContext queryContext) { _queryContext = queryContext; } - public async Task> Handle(GetUserDetailsQuery request, CancellationToken ct) + public async Task> Handle(GetAccountDetailsQuery request, CancellationToken ct) { var user = await _queryContext.Users .Where(user => user.Id == request.UserId) - .Select(user => new UserResponse + .Select(user => new AccountResponse { Email = user.Email, Name = user.Name, diff --git a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQuery.cs b/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQuery.cs deleted file mode 100644 index b3786e5..0000000 --- a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQuery.cs +++ /dev/null @@ -1,7 +0,0 @@ -using TeamUp.Application.Abstractions; -using TeamUp.Common; -using TeamUp.Contracts.Users; - -namespace TeamUp.Application.Users.GetUserDetail; - -public sealed record GetUserDetailsQuery(UserId UserId) : IQuery>; diff --git a/src/TeamUp.Contracts/Users/UserResponse.cs b/src/TeamUp.Contracts/Users/AccountResponse.cs similarity index 83% rename from src/TeamUp.Contracts/Users/UserResponse.cs rename to src/TeamUp.Contracts/Users/AccountResponse.cs index 47250ef..a77fd1a 100644 --- a/src/TeamUp.Contracts/Users/UserResponse.cs +++ b/src/TeamUp.Contracts/Users/AccountResponse.cs @@ -1,6 +1,6 @@ namespace TeamUp.Contracts.Users; -public sealed class UserResponse +public sealed class AccountResponse { public required string Email { get; set; } public required string Name { get; set; } diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs index 847e7af..6ead5cd 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; +using TeamUp.Contracts.Invitations; using TeamUp.Contracts.Teams; namespace TeamUp.EndToEndTests.EndpointTests.Invitations; @@ -8,6 +9,9 @@ public sealed class AcceptInvitationTests : BaseInvitationTests { public AcceptInvitationTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(InvitationId invitationId) => GetUrl(invitationId.Value); + public static string GetUrl(Guid invitationId) => $"/api/v1/invitations/{invitationId}/accept"; + [Fact] public async Task AcceptInvitation_ThatIsValid_AsRecipient_Should_RemoveInvitationFromDatabase_And_AddUserAsMemberToTeamInDatabase() { @@ -30,7 +34,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.PostAsync($"/api/v1/invitations/{invitation.Id.Value}/accept", null); + var response = await Client.PostAsync(GetUrl(invitation.Id), null); //assert response.Should().Be200Ok(); @@ -75,7 +79,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.PostAsync($"/api/v1/invitations/{invitation.Id.Value}/accept", null); + var response = await Client.PostAsync(GetUrl(invitation.Id), null); //assert response.Should().Be400BadRequest(); @@ -101,11 +105,10 @@ await UseDbContextAsync(dbContext => dbContext.Teams.Add(team); return dbContext.SaveChangesAsync(); }); - Authenticate(initiatorUser); //act - var response = await Client.PostAsync($"/api/v1/invitations/{invitationId}/accept", null); + var response = await Client.PostAsync(GetUrl(invitationId), null); //assert response.Should().Be404NotFound(); @@ -137,7 +140,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.PostAsync($"/api/v1/invitations/{invitation.Id.Value}/accept", null); + var response = await Client.PostAsync(GetUrl(invitation.Id), null); //assert response.Should().Be403Forbidden(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs index 5cea7ee..5c79ff0 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs @@ -7,6 +7,9 @@ public sealed class GetTeamInvitationsTests : BaseInvitationTests { public GetTeamInvitationsTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/invitations/teams/{teamId}"; + [Theory] [InlineData(TeamRole.Coordinator)] [InlineData(TeamRole.Admin)] @@ -34,7 +37,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/invitations/teams/{team.Id.Value}"); + var response = await Client.GetAsync(GetUrl(team.Id)); //assert response.Should().Be200Ok(); @@ -64,7 +67,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/invitations/teams/{team.Id.Value}"); + var response = await Client.GetAsync(GetUrl(team.Id)); //assert response.Should().Be403Forbidden(); @@ -95,7 +98,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/invitations/teams/{team.Id.Value}"); + var response = await Client.GetAsync(GetUrl(team.Id)); //assert response.Should().Be403Forbidden(); @@ -120,7 +123,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/invitations/teams/{teamId}"); + var response = await Client.GetAsync(GetUrl(teamId)); //assert response.Should().Be404NotFound(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs index 6cb973c..4d3b1ea 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs @@ -8,6 +8,8 @@ public sealed class InviteUserTests : BaseInvitationTests { public InviteUserTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public const string URL = "/api/v1/invitations"; + [Theory] [InlineData(TeamRole.Coordinator)] [InlineData(TeamRole.Admin)] @@ -37,7 +39,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be201Created(); @@ -84,7 +86,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be201Created(); @@ -138,7 +140,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be400BadRequest(); @@ -173,7 +175,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be403Forbidden(); @@ -213,7 +215,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be409Conflict(); @@ -249,7 +251,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be403Forbidden(); @@ -280,7 +282,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be404NotFound(); @@ -305,7 +307,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.PostAsJsonAsync("/api/v1/invitations", request.Request); + var response = await Client.PostAsJsonAsync(URL, request.Request); //assert response.Should().Be400BadRequest(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs index e6ac0cf..59f022c 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs @@ -8,6 +8,9 @@ public sealed class ChangeNicknameTests : BaseTeamTests { public ChangeNicknameTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}/nickname"; + [Theory] [InlineData(TeamRole.Member)] [InlineData(TeamRole.Coordinator)] @@ -37,7 +40,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/nickname", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be200Ok(); @@ -78,7 +81,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/nickname", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be403Forbidden(); @@ -108,7 +111,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{teamId}/nickname", request); + var response = await Client.PutAsJsonAsync(GetUrl(teamId), request); //assert response.Should().Be404NotFound(); @@ -146,7 +149,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/nickname", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be400BadRequest(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs index c98ad1e..7a6a672 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs @@ -8,6 +8,9 @@ public sealed class ChangeOwnershipTests : BaseTeamTests { public ChangeOwnershipTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}/owner"; + [Theory] [InlineData(TeamRole.Member)] [InlineData(TeamRole.Coordinator)] @@ -33,7 +36,7 @@ await UseDbContextAsync(dbContext => var targetMemberId = team.Members.First(member => member.UserId == targetUser.Id).Id; //assert - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/owner", targetMemberId.Value); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), targetMemberId.Value); //act response.Should().Be200Ok(); @@ -46,11 +49,11 @@ await UseDbContextAsync(dbContext => .ToListAsync(); }); - var originalOwner = teamMembers.FirstOrDefault(member => member.UserId == owner.Id); + var originalOwner = teamMembers.SingleOrDefault(member => member.UserId == owner.Id); originalOwner.ShouldNotBeNull(); originalOwner.Role.Should().Be(TeamRole.Admin); - var newOwner = teamMembers.FirstOrDefault(member => member.UserId == targetUser.Id); + var newOwner = teamMembers.SingleOrDefault(member => member.UserId == targetUser.Id); newOwner.ShouldNotBeNull(); newOwner.Role.Should().Be(TeamRole.Owner); @@ -92,7 +95,7 @@ await UseDbContextAsync(dbContext => var targetMemberId = team.Members.First(member => member.UserId == initiatorUser.Id).Id; //assert - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/owner", targetMemberId.Value); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), targetMemberId.Value); //act response.Should().Be403Forbidden(); @@ -122,7 +125,7 @@ await UseDbContextAsync(dbContext => var targetMemberId = F.Random.Guid(); //assert - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/owner", targetMemberId); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), targetMemberId); //act response.Should().Be404NotFound(); @@ -154,7 +157,7 @@ await UseDbContextAsync(dbContext => var targetMemberId = team.Members.First(member => member.UserId == targetUser.Id).Id.Value; //assert - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/owner", targetMemberId); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id), targetMemberId); //act response.Should().Be403Forbidden(); @@ -181,7 +184,7 @@ await UseDbContextAsync(dbContext => var targetMemberId = F.Random.Guid(); //assert - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{teamId}/owner", targetMemberId); + var response = await Client.PutAsJsonAsync(GetUrl(teamId), targetMemberId); //act response.Should().Be404NotFound(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs index 703e7a4..ec684bb 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs @@ -6,6 +6,9 @@ public sealed class CreateEventTypeTests : BaseTeamTests { public CreateEventTypeTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}/event-types"; + [Theory] [InlineData(TeamRole.Coordinator)] [InlineData(TeamRole.Admin)] @@ -30,7 +33,7 @@ await UseDbContextAsync(dbContext => var request = TeamGenerator.ValidUpsertEventTypeRequest.Generate(); //act - var response = await Client.PostAsJsonAsync($"/api/v1/teams/{team.Id.Value}/event-types", request); + var response = await Client.PostAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be201Created(); @@ -72,7 +75,7 @@ await UseDbContextAsync(dbContext => var request = TeamGenerator.ValidUpsertEventTypeRequest.Generate(); //act - var response = await Client.PostAsJsonAsync($"/api/v1/teams/{team.Id.Value}/event-types", request); + var response = await Client.PostAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be403Forbidden(); @@ -103,7 +106,7 @@ await UseDbContextAsync(dbContext => var request = TeamGenerator.ValidUpsertEventTypeRequest.Generate(); //act - var response = await Client.PostAsJsonAsync($"/api/v1/teams/{team.Id.Value}/event-types", request); + var response = await Client.PostAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be403Forbidden(); @@ -130,7 +133,7 @@ await UseDbContextAsync(dbContext => var request = TeamGenerator.ValidUpsertEventTypeRequest.Generate(); //act - var response = await Client.PostAsJsonAsync($"/api/v1/teams/{teamId}/event-types", request); + var response = await Client.PostAsJsonAsync(GetUrl(teamId), request); //assert response.Should().Be404NotFound(); @@ -159,7 +162,7 @@ await UseDbContextAsync(dbContext => Authenticate(owner); //act - var response = await Client.PostAsJsonAsync($"/api/v1/teams/{team.Id.Value}/event-types", request.Request); + var response = await Client.PostAsJsonAsync(GetUrl(team.Id), request.Request); //assert response.Should().Be400BadRequest(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs index 097d0f4..802f8ca 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs @@ -8,6 +8,8 @@ public sealed class CreateTeamTests : BaseTeamTests { public CreateTeamTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public const string URL = "/api/v1/teams"; + [Fact] public async Task CreateTeam_Should_CreateNewTeamInDatabase_WithOneTeamOwner() { @@ -27,7 +29,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/teams", createTeamRequest); + var response = await Client.PostAsJsonAsync(URL, createTeamRequest); //assert response.Should().Be201Created(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs index 77f6ead..1fbd9d0 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs @@ -8,6 +8,9 @@ public sealed class DeleteTeamTests : BaseTeamTests { public DeleteTeamTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}"; + [Fact] public async Task DeleteTeam_AsOwner_Should_DeleteTeamInDatabase() { @@ -27,7 +30,7 @@ await UseDbContextAsync(dbContext => Authenticate(owner); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id)); //assert response.Should().Be200Ok(); @@ -74,7 +77,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id)); //assert response.Should().Be403Forbidden(); @@ -95,11 +98,10 @@ await UseDbContextAsync(dbContext => dbContext.Users.Add(user); return dbContext.SaveChangesAsync(); }); - Authenticate(user); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{teamId}"); + var response = await Client.DeleteAsync(GetUrl(teamId)); //assert response.Should().Be404NotFound(); @@ -128,7 +130,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id)); //assert response.Should().Be403Forbidden(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs index 5db9392..a18bd28 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs @@ -6,6 +6,9 @@ public sealed class GetTeamTests : BaseTeamTests { public GetTeamTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}"; + [Fact] public async Task GetTeam_ThatDoesNotExist_Should_ResultInNotFound() { @@ -18,11 +21,10 @@ await UseDbContextAsync(dbContext => dbContext.Users.Add(user); return dbContext.SaveChangesAsync(); }); - Authenticate(user); //act - var response = await Client.GetAsync($"/api/v1/teams/{teamId}"); + var response = await Client.GetAsync(GetUrl(teamId)); //assert response.Should().Be404NotFound(); @@ -54,7 +56,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/teams/{team.Id.Value}"); + var response = await Client.GetAsync(GetUrl(team.Id)); //assert response.Should().Be200Ok(); @@ -89,7 +91,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.GetAsync($"/api/v1/teams/{team.Id.Value}"); + var response = await Client.GetAsync(GetUrl(team.Id)); //assert response.Should().Be403Forbidden(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs index eef5f58..6fd4013 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs @@ -6,6 +6,9 @@ public sealed class RemoveTeamMemberTests : BaseTeamTests { public RemoveTeamMemberTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId, TeamMemberId memberId) => GetUrl(teamId.Value, memberId.Value); + public static string GetUrl(Guid teamId, Guid memberId) => $"/api/v1/teams/{teamId}/members/{memberId}"; + [Theory] [InlineData(TeamRole.Admin, TeamRole.Member)] [InlineData(TeamRole.Admin, TeamRole.Coordinator)] @@ -34,7 +37,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be200Ok(); @@ -74,7 +77,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be200Ok(); @@ -115,7 +118,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be403Forbidden(); @@ -145,7 +148,7 @@ await UseDbContextAsync(dbContext => Authenticate(owner); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be400BadRequest(); @@ -176,7 +179,7 @@ await UseDbContextAsync(dbContext => Authenticate(owner); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be400BadRequest(); @@ -206,7 +209,7 @@ await UseDbContextAsync(dbContext => Authenticate(owner); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId}"); + var response = await Client.DeleteAsync(GetUrl(team.Id.Value, targetMemberId)); //assert response.Should().Be404NotFound(); @@ -229,11 +232,10 @@ await UseDbContextAsync(dbContext => dbContext.Users.Add(user); return dbContext.SaveChangesAsync(); }); - Authenticate(user); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{teamId}/{targetMemberId}"); + var response = await Client.DeleteAsync(GetUrl(teamId, targetMemberId)); //assert response.Should().Be404NotFound(); @@ -264,7 +266,7 @@ await UseDbContextAsync(dbContext => Authenticate(initiatorUser); //act - var response = await Client.DeleteAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}"); + var response = await Client.DeleteAsync(GetUrl(team.Id, targetMemberId)); //assert response.Should().Be403Forbidden(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs index 0cb7c10..ff4364f 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs @@ -8,6 +8,10 @@ public sealed class UpdateTeamMemberRoleTests : BaseTeamTests { public UpdateTeamMemberRoleTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId, TeamMemberId memberId) => GetUrl(teamId.Value, memberId.Value); + public static string GetUrl(Guid teamId, Guid memberId) => $"/api/v1/teams/{teamId}/members/{memberId}/role"; + + [Theory] [InlineData(TeamRole.Admin, TeamRole.Member, TeamRole.Admin)] [InlineData(TeamRole.Admin, TeamRole.Member, TeamRole.Coordinator)] @@ -46,7 +50,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id, targetMemberId), request); //assert response.Should().Be200Ok(); @@ -107,7 +111,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id, targetMemberId), request); //assert response.Should().Be403Forbidden(); @@ -147,7 +151,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id, targetMemberId), request); //assert response.Should().Be400BadRequest(); @@ -186,7 +190,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id, targetMemberId), request); //assert response.Should().Be400BadRequest(); @@ -220,7 +224,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id.Value, targetMemberId), request); //assert response.Should().Be404NotFound(); @@ -251,7 +255,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{teamId}/{targetMemberId}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(teamId, targetMemberId), request); //assert response.Should().Be404NotFound(); @@ -286,7 +290,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PutAsJsonAsync($"/api/v1/teams/{team.Id.Value}/{targetMemberId.Value}/role", request); + var response = await Client.PutAsJsonAsync(GetUrl(team.Id, targetMemberId), request); //assert response.Should().Be403Forbidden(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs index c6d96ed..701822d 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs @@ -6,6 +6,9 @@ public sealed class UpdateTeamNameTests : BaseTeamTests { public UpdateTeamNameTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(TeamId teamId) => GetUrl(teamId.Value); + public static string GetUrl(Guid teamId) => $"/api/v1/teams/{teamId}"; + [Fact] public async Task UpdateTeamName_AsOwner_Should_UpdateTeamNameInDatabase() { @@ -30,7 +33,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PatchAsJsonAsync($"/api/v1/teams/{team.Id.Value}", request); + var response = await Client.PatchAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be200Ok(); @@ -68,7 +71,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PatchAsJsonAsync($"/api/v1/teams/{team.Id.Value}", request); + var response = await Client.PatchAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be403Forbidden(); @@ -98,7 +101,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PatchAsJsonAsync($"/api/v1/teams/{teamId}", request); + var response = await Client.PatchAsJsonAsync(GetUrl(teamId), request); //assert response.Should().Be404NotFound(); @@ -132,7 +135,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PatchAsJsonAsync($"/api/v1/teams/{team.Id.Value}", request); + var response = await Client.PatchAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be403Forbidden(); @@ -168,7 +171,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PatchAsJsonAsync($"/api/v1/teams/{team.Id.Value}", request); + var response = await Client.PatchAsJsonAsync(GetUrl(team.Id), request); //assert response.Should().Be400BadRequest(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs index f0c83f0..8799add 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs @@ -6,6 +6,9 @@ public sealed class ActivateAccountTests : BaseUserAccessTests { public ActivateAccountTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public static string GetUrl(UserId userId) => GetUrl(userId.Value); + public static string GetUrl(Guid userId) => $"/api/v1/users/{userId}/activate"; + [Fact] public async Task ActivateAccount_Should_SetUserStatusAsActivatedInDatabase() { @@ -19,7 +22,7 @@ await UseDbContextAsync(dbContext => }); //act - var response = await Client.PostAsJsonAsync($"/api/v1/users/{user.Id.Value}/activate", EmptyObject); + var response = await Client.PostAsJsonAsync(GetUrl(user.Id), EmptyObject); //assert response.Should().Be200Ok(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs similarity index 65% rename from tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs rename to tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs index d33329d..e1d0b17 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs @@ -2,16 +2,18 @@ namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; -public sealed class GetUserDetailsTests : BaseUserAccessTests +public sealed class GetMyAccountDetailsTests : BaseUserAccessTests { - public GetUserDetailsTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public GetMyAccountDetailsTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + + public const string URL = "/api/v1/users"; [Fact] public async Task GetMyProfile_WhenUnauthenticated_Should_ResultInUnauthorized() { //arrange //act - var response = await Client.GetAsync("/api/v1/users"); + var response = await Client.GetAsync(URL); //assert response.Should().Be401Unauthorized(); @@ -32,12 +34,12 @@ await UseDbContextAsync(dbContext => Authenticate(user); //act - var response = await Client.GetAsync("/api/v1/users"); + var response = await Client.GetAsync(URL); //assert response.Should().Be200Ok(); - var userResponse = await response.ReadFromJsonAsync(); + var userResponse = await response.ReadFromJsonAsync(); user.Should().BeEquivalentTo(userResponse, o => o.ExcludingMissingMembers()); } } diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs index 408d446..491ef8e 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs @@ -10,6 +10,8 @@ public sealed class LoginTests : BaseUserAccessTests { public LoginTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public const string URL = "/api/v1/users/login"; + [Fact] public async Task Login_AsActivatedUser_Should_GenerateValidJwtToken() { @@ -32,7 +34,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/users/login", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be200Ok(); @@ -76,7 +78,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/users/login", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be401Unauthorized(); @@ -97,7 +99,7 @@ public async Task Login_AsUnExistingUser_Should_ResultInUnauthorized() }; //act - var response = await Client.PostAsJsonAsync("/api/v1/users/login", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be401Unauthorized(); @@ -128,7 +130,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/users/login", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be401Unauthorized(); @@ -136,5 +138,4 @@ await UseDbContextAsync(dbContext => var problemDetails = await response.ReadProblemDetailsAsync(); problemDetails.ShouldContainError(AuthenticationErrors.InvalidCredentials); } - } diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs index 97c6cce..4addd85 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs @@ -6,6 +6,8 @@ public sealed class RegisterUserTests : BaseUserAccessTests { public RegisterUserTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public const string URL = "/api/v1/users/register"; + [Fact] public async Task RegisterUser_Should_CreateNewUserInDatabase_And_SendActivationEmail() { @@ -13,7 +15,7 @@ public async Task RegisterUser_Should_CreateNewUserInDatabase_And_SendActivation var request = UserGenerator.ValidRegisterUserRequest.Generate(); //act - var response = await Client.PostAsJsonAsync("/api/v1/users/register", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be201Created(); @@ -52,7 +54,7 @@ await UseDbContextAsync(dbContext => }; //act - var response = await Client.PostAsJsonAsync("/api/v1/users/register", request); + var response = await Client.PostAsJsonAsync(URL, request); //assert response.Should().Be409Conflict(); @@ -67,7 +69,7 @@ public async Task RegisterUser_WithInvalidProperties_Should_ResultInValidationEr { //arrange //act - var response = await Client.PostAsJsonAsync("/api/v1/users/register", request.Request); + var response = await Client.PostAsJsonAsync(URL, request.Request); //assert response.Should().Be400BadRequest(); @@ -75,5 +77,4 @@ public async Task RegisterUser_WithInvalidProperties_Should_ResultInValidationEr var problemDetails = await response.ReadValidationProblemDetailsAsync(); problemDetails.ShouldContainValidationErrorFor(request.InvalidProperty); } - }