@@ -193,4 +193,54 @@ public async Task WhenPutClientsWithValidData_ShouldUpdateClientSuccessfully()
193193
194194 Assert . Contains ( persistedClient . RedirectUris , uri => uri . Address == "https://localhost/callback" ) ;
195195 }
196+
197+ [ Fact ( DisplayName = "[e2e] - when DELETE /clients/{id} with valid client should delete client successfully" ) ]
198+ public async Task WhenDeleteClientsWithValidClient_ShouldDeleteClientSuccessfully ( )
199+ {
200+ /* arrange: resolve required dependencies */
201+ var clientCollection = factory . Services . GetRequiredService < IClientCollection > ( ) ;
202+
203+ /* arrange: authenticate user and get access token */
204+ var httpClient = factory . HttpClient . WithRealmHeader ( "master" ) ;
205+ var credentials = new AuthenticationCredentials
206+ {
207+ Username = "federation.testing.user" ,
208+ Password = "federation.testing.password"
209+ } ;
210+
211+ var authenticationResponse = await httpClient . PostAsJsonAsync ( "api/v1/identity/authenticate" , credentials ) ;
212+ var authenticationResult = await authenticationResponse . Content . ReadFromJsonAsync < AuthenticationResult > ( ) ;
213+
214+ Assert . NotNull ( authenticationResult ) ;
215+ Assert . NotEmpty ( authenticationResult . AccessToken ) ;
216+
217+ httpClient . WithAuthorization ( authenticationResult . AccessToken ) ;
218+
219+ /* arrange: create a new client to delete */
220+ var payload = _fixture . Build < ClientCreationScheme > ( )
221+ . With ( client => client . Name , $ "test-client-{ Guid . NewGuid ( ) } ")
222+ . With ( client => client . Flows , [ Grant . ClientCredentials ] )
223+ . With ( client => client . RedirectUris , [ ] )
224+ . Create ( ) ;
225+
226+ var createResponse = await httpClient . PostAsJsonAsync ( "api/v1/clients" , payload ) ;
227+ var filters = ClientFilters . WithSpecifications ( )
228+ . WithName ( payload . Name )
229+ . Build ( ) ;
230+
231+ Assert . Equal ( HttpStatusCode . Created , createResponse . StatusCode ) ;
232+
233+ var clients = await clientCollection . GetClientsAsync ( filters , CancellationToken . None ) ;
234+ var client = clients . FirstOrDefault ( ) ;
235+
236+ Assert . NotEmpty ( clients ) ;
237+ Assert . NotNull ( client ) ;
238+
239+ /* act: send DELETE request to remove client */
240+ var response = await httpClient . DeleteAsync ( $ "api/v1/clients/{ client . Id } ") ;
241+ var result = await clientCollection . GetClientsAsync ( filters , CancellationToken . None ) ;
242+
243+ Assert . Equal ( HttpStatusCode . NoContent , response . StatusCode ) ;
244+ Assert . DoesNotContain ( result , current => current . Id == client . Id ) ;
245+ }
196246}
0 commit comments