Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly pass null when rolling out user from the enterprise #792

Merged
merged 3 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Box.V2.Test/BoxUsersManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,39 @@ public async Task UpdateUser_ValidResponse_ValidUser()
Assert.AreEqual("[email protected]", user.NotificationEmail.Email);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task RolloutUserFromEnterprise_ValidResponse_ValidUser()
{
/*** Arrange ***/
var responseString = "{\"type\":\"user\",\"id\":\"181216415\",\"name\":\"sean\",\"login\":\"[email protected]\",\"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\": \"[email protected]\", \"is_confirmed\": true}}";
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxUser>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxUser>>(new BoxResponse<BoxUser>()
{
Status = ResponseStatus.Success,
ContentString = responseString
}))
.Callback<IBoxRequest>(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<BoxUserRequest>(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()
Expand Down
1 change: 1 addition & 0 deletions Box.V2/Box.V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<Compile Include="Models\Request\BoxFileUploadSessionRequest.cs" />
<Compile Include="Models\Request\BoxSignRequestCreateRequest.cs" />
<Compile Include="Models\Request\BoxTermsOfServiceUserStatusCreateRequest.cs" />
<Compile Include="Models\Request\BoxUserRolloutRequest.cs" />
<Compile Include="Models\Request\BoxZipRequest.cs" />
<Compile Include="Models\Request\BoxLegalHoldPolicyAssignmentRequest.cs" />
<Compile Include="Models\Request\BoxLegalHoldPolicyRequest.cs" />
Expand Down
17 changes: 17 additions & 0 deletions Box.V2/Models/Request/BoxUserRolloutRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;

namespace Box.V2.Models
{
/// <summary>
/// A request class for rolling users out of the enterprise.
/// </summary>
public class BoxUserRollOutRequest : BoxUserRequest
{
/// <summary>
/// Setting this to null will roll the user out of the enterprise and make them a free user
/// </summary>
[JsonProperty(PropertyName = "enterprise", NullValueHandling = NullValueHandling.Include)]
public new string Enterprise { get; set; }

}
}