From c85c5735865b7dd97ffa1428a8f57d2edff6811b Mon Sep 17 00:00:00 2001 From: Mateusz Woda Date: Mon, 10 Jan 2022 06:52:21 -0800 Subject: [PATCH] fix: correctly pass null when rolling out user from the enterprise (#792) Co-authored-by: Jonathan Black <45244911+jblack6-byu@users.noreply.github.com> --- Box.V2.Test/BoxUsersManagerTest.cs | 33 +++++++++++++++++++ Box.V2/Box.V2.csproj | 1 + .../Models/Request/BoxUserRolloutRequest.cs | 17 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Box.V2/Models/Request/BoxUserRolloutRequest.cs diff --git a/Box.V2.Test/BoxUsersManagerTest.cs b/Box.V2.Test/BoxUsersManagerTest.cs index d76b7a9f1..ac9bc950a 100644 --- a/Box.V2.Test/BoxUsersManagerTest.cs +++ b/Box.V2.Test/BoxUsersManagerTest.cs @@ -206,6 +206,39 @@ public async Task UpdateUser_ValidResponse_ValidUser() Assert.AreEqual("test@example.com", user.NotificationEmail.Email); } + [TestMethod] + [TestCategory("CI-UNIT-TEST")] + public async Task RolloutUserFromEnterprise_ValidResponse_ValidUser() + { + /*** Arrange ***/ + var responseString = "{\"type\":\"user\",\"id\":\"181216415\",\"name\":\"sean\",\"login\":\"sean+awesome@box.com\",\"created_at\":\"2012-05-03T21:39:11-07:00\",\"modified_at\":\"2012-12-06T18:17:16-08:00\",\"role\":\"admin\",\"language\":\"en\",\"space_amount\":5368709120,\"space_used\":1237179286,\"max_upload_size\":2147483648,\"tracking_codes\":[],\"can_see_managed_users\":true,\"is_sync_enabled\":true,\"status\":\"active\",\"job_title\":\"\",\"phone\":\"6509241374\",\"address\":\"\",\"avatar_url\":\"https://www.box.com/api/avatar/large/181216415\",\"is_exempt_from_device_limits\":false,\"is_exempt_from_login_verification\":false, \"notification_email\": { \"email\": \"test@example.com\", \"is_confirmed\": true}}"; + IBoxRequest boxRequest = null; + Handler.Setup(h => h.ExecuteAsync(It.IsAny())) + .Returns(Task.FromResult>(new BoxResponse() + { + Status = ResponseStatus.Success, + ContentString = responseString + })) + .Callback(r => boxRequest = r); + + /*** Act ***/ + var userRequest = new BoxUserRollOutRequest() + { + Id = "181216415", + }; + BoxUser user = await _usersManager.UpdateUserInformationAsync(userRequest); + + /*** Assert ***/ + + // Request check + Assert.IsNotNull(boxRequest); + Assert.AreEqual(RequestMethod.Put, boxRequest.Method); + Assert.AreEqual(UserUri + "181216415", boxRequest.AbsoluteUri.AbsoluteUri); + BoxUserRequest payload = JsonConvert.DeserializeObject(boxRequest.Payload); + Assert.AreEqual(userRequest.Id, payload.Id); + Assert.AreEqual(boxRequest.Payload, "{\"enterprise\":null,\"id\":\"181216415\"}"); + } + [TestMethod] [TestCategory("CI-UNIT-TEST")] public async Task InviteUser_ValidResponse_ValidUser() diff --git a/Box.V2/Box.V2.csproj b/Box.V2/Box.V2.csproj index 34021489c..f5ed6f2f6 100644 --- a/Box.V2/Box.V2.csproj +++ b/Box.V2/Box.V2.csproj @@ -210,6 +210,7 @@ + diff --git a/Box.V2/Models/Request/BoxUserRolloutRequest.cs b/Box.V2/Models/Request/BoxUserRolloutRequest.cs new file mode 100644 index 000000000..065086eb2 --- /dev/null +++ b/Box.V2/Models/Request/BoxUserRolloutRequest.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace Box.V2.Models +{ + /// + /// A request class for rolling users out of the enterprise. + /// + public class BoxUserRollOutRequest : BoxUserRequest + { + /// + /// Setting this to null will roll the user out of the enterprise and make them a free user + /// + [JsonProperty(PropertyName = "enterprise", NullValueHandling = NullValueHandling.Include)] + public new string Enterprise { get; set; } + + } +}