mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Add basic tests for delete user endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -19,5 +20,12 @@ namespace BTCPayServer.Client
|
|||||||
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users", null, request, HttpMethod.Post), token);
|
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users", null, request, HttpMethod.Post), token);
|
||||||
return await HandleResponse<ApplicationUserData>(response);
|
return await HandleResponse<ApplicationUserData>(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<HttpResponseMessage> DeleteUser(string userId, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{userId}", null, HttpMethod.Delete), token);
|
||||||
|
await HandleResponse(response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,28 @@ namespace BTCPayServer.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact(Timeout = TestTimeout)]
|
||||||
|
[Trait("Integration", "Integration")]
|
||||||
|
public async Task CanDeleteUsersViaApi()
|
||||||
|
{
|
||||||
|
using (var tester = ServerTester.Create(newDb: true))
|
||||||
|
{
|
||||||
|
await tester.StartAsync();
|
||||||
|
var unauthClient = new BTCPayServerClient(tester.PayTester.ServerUri);
|
||||||
|
// Should not be authorized to perform this action
|
||||||
|
await AssertHttpError(401,
|
||||||
|
async () => await unauthClient.DeleteUser("lol user id"));
|
||||||
|
|
||||||
|
var user = tester.NewAccount();
|
||||||
|
user.GrantAccess();
|
||||||
|
await user.MakeAdmin();
|
||||||
|
var adminClient = await user.CreateClient(Policies.Unrestricted);
|
||||||
|
// Should 404 if user doesn't exist
|
||||||
|
await AssertHttpError(404,
|
||||||
|
async () => await adminClient.DeleteUser("lol user id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact(Timeout = TestTimeout)]
|
[Fact(Timeout = TestTimeout)]
|
||||||
[Trait("Integration", "Integration")]
|
[Trait("Integration", "Integration")]
|
||||||
public async Task CanCreateUsersViaAPI()
|
public async Task CanCreateUsersViaAPI()
|
||||||
|
|||||||
Reference in New Issue
Block a user