Skip to content

Commit

Permalink
Add Subusers feature #deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
jakublabno committed Dec 18, 2024
1 parent 16410aa commit 388052d
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
19 changes: 19 additions & 0 deletions smsapi/Api/Action/Subusers/Creation/DeleteSubuser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using SMSApi.Api.Response.Subusers;

namespace SMSApi.Api.Action.Subusers.Creation;

public sealed class DeleteSubuser : Action<SubuserDeletionResult>
{
private readonly string _userId;

public DeleteSubuser(string userId)
{
_userId = userId;
}

protected override RequestMethod Method => RequestMethod.DELETE;

protected override string Uri() => $"subusers/{_userId}";

protected override ApiType ApiType() => Action.ApiType.Rest;
}
7 changes: 7 additions & 0 deletions smsapi/Api/Response/Subusers/SubuserDeletionResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using SMSApi.Api.Response.ResponseResolver;

namespace SMSApi.Api.Response.Subusers;

public sealed class SubuserDeletionResult : IResponseCodeAwareResolver
{
}
9 changes: 9 additions & 0 deletions smsapi/Api/SubUsersFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public GetSubuser Get(string userId)

return action;
}

public DeleteSubuser Delete(string userId)
{
var action = new DeleteSubuser(userId);

action.Proxy(proxy);

return action;
}
}

public static class SubusersFeatureRegister
Expand Down
50 changes: 50 additions & 0 deletions smsapiTests/Unit/Action/Subusers/DeleteSubuserResponseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SMSApi.Api;
using SMSApi.Api.Action.Subusers.Creation;
using smsapi.Api.Response.REST.Exception;
using smsapiTests.Unit.Fixture;
using smsapiTests.Unit.Helper;

namespace smsapiTests.Unit.Action.Subusers;

[TestClass]
public class DeleteSubuserResponseTest
{
private readonly ProxyStub _proxyStub = new();

[TestMethod]
public void delete_subuser()
{
var subuserId = "1238f47da26ee45dc41fb987";
_proxyStub.SyncExecutionResponse = new HttpResponseEntity(
DictionaryToStreamHelper.EmptyStream,
HttpStatusCode.NoContent
);

DeleteSubuser(subuserId);

Assert.IsTrue(true);
}

[TestMethod]
public void map_http_404_to_not_found_exception()
{
_proxyStub.SyncExecutionResponse = new HttpResponseEntity(
DictionaryToStreamHelper.EmptyStream,
HttpStatusCode.NotFound
);

var result = () => { DeleteSubuser(); };

Assert.ThrowsException<NotFoundException>(result);
}

private void DeleteSubuser(string userId = "any")
{
var action = new DeleteSubuser(userId);
action.Proxy(_proxyStub);

action.Execute();
}
}
43 changes: 43 additions & 0 deletions smsapiTests/Unit/Action/Subusers/DeleteSubuserTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SMSApi.Api;
using SMSApi.Api.Action.Subusers.Creation;

namespace smsapiTests.Unit.Action.Subusers;

[TestClass]
public class DeleteSubuserTest
{
private readonly ProxyAssert _proxyAssert;
private readonly SpyProxy _spyProxy = new();

public DeleteSubuserTest()
{
_proxyAssert = new ProxyAssert(_spyProxy);
}

[TestMethod]
public void use_delete_request_method()
{
DeleteSubuser();

_proxyAssert.AssertRequestMethod(RequestMethod.DELETE);
}

[TestMethod]
public void request_proper_uri()
{
var userId = "1238f47da26ee45dc41fb987";

DeleteSubuser(userId);

_proxyAssert.AssertUriEquals($"subusers/{userId}");
}

private void DeleteSubuser(string userId = "any")
{
var action = new DeleteSubuser(userId);
action.Proxy(_spyProxy);

action.Execute();
}
}

0 comments on commit 388052d

Please sign in to comment.