backend: Expand backend integration test coverage
This commit is contained in:
1 parent
ce04c8beb3
commit
32bc5a4691
8 files changed
+500
-19
No files matched your search
@@ -12,6 +12,27 @@ namespace Helpdesk.IntegrationTests;
|
||||
|
||||
public sealed class AuthTests(BackendFixture fixture) : IClassFixture<BackendFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task ChangingPasswordThroughAnEmailLinkRevokesTheOldSession()
|
||||
{
|
||||
using var anonymous = fixture.CreateClient();
|
||||
var user = await fixture.RegisterAsync(anonymous);
|
||||
using var oldSession = fixture.CreateClient((await LoginAsync(anonymous, user.Email)).AccessToken);
|
||||
await ExpectAsync(anonymous.PostAsJsonAsync("/api/v1/auth/forgot-password",
|
||||
new ForgotPasswordRequest(user.Email), Cancellation), HttpStatusCode.NoContent);
|
||||
|
||||
const string newPassword = "New-integration-password";
|
||||
var reset = new ResetPasswordRequest(await fixture.TakeResetTokenAsync(user.Email), newPassword);
|
||||
await ExpectAsync(anonymous.PostAsJsonAsync("/api/v1/auth/reset-password", reset, Cancellation), HttpStatusCode.NoContent);
|
||||
await ExpectAsync(anonymous.PostAsJsonAsync("/api/v1/auth/reset-password", reset, Cancellation), HttpStatusCode.BadRequest);
|
||||
await ExpectAsync(oldSession.GetAsync("/api/v1/users/me", Cancellation), HttpStatusCode.Unauthorized);
|
||||
await ExpectAsync(anonymous.PostAsJsonAsync("/api/v1/auth/login",
|
||||
new LoginRequest(user.Email, Password), Cancellation), HttpStatusCode.Unauthorized);
|
||||
var session = await ReadAsync<AuthResponse>(anonymous.PostAsJsonAsync("/api/v1/auth/login",
|
||||
new LoginRequest(user.Email, newPassword), Cancellation));
|
||||
Assert.Equal(user.Id, session.User.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LogoutRevokesOnlyTheCurrentSession()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user