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

Added support for Task completion_rule field #758

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 75 additions & 1 deletion Box.V2.Test/BoxTasksManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ public async Task CreateTask_ValidResponse()
""name"": ""sean"",
""login"": ""sean@box.com""
},
""created_at"": ""2013-04-03T11:12:54-07:00""
""created_at"": ""2013-04-03T11:12:54-07:00"",
""completion_rule"": ""all_assignees""
}";
IBoxRequest boxRequest = null;
Uri tasksUri = new Uri(Constants.TasksEndpointString);
Expand Down Expand Up @@ -399,6 +400,7 @@ public async Task CreateTask_ValidResponse()
Assert.AreEqual(taskCreateRequest.Item.Id, payload.Item.Id);
Assert.AreEqual(taskCreateRequest.Item.Type, payload.Item.Type);
Assert.AreEqual(taskCreateRequest.Message, payload.Message);
Assert.IsNull(payload.CompletionRule);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check it explicitly? I don't see any reason to do this in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure i can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait... this one is useful. Without it CompletionRule could be not marked as optional and then this field is automatically set to first value from enum BoxCompletionRule. I could move it to dedicated test?


//Response check
Assert.AreEqual("1839355", result.Id);
Expand All @@ -411,7 +413,79 @@ public async Task CreateTask_ValidResponse()
Assert.AreEqual("11993747", result.CreatedBy.Id);
Assert.AreEqual("sean@box.com", result.CreatedBy.Login);
Assert.AreEqual(0, result.TaskAssignments.TotalCount);
Assert.AreEqual(BoxCompletionRule.all_assignees, result.CompletionRule);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task CreateTask_WithCompletionRule()
{
/*** Arrange ***/
string responseString = @"{
""type"": ""task"",
""id"": ""1839355"",
""item"": {
""type"": ""file"",
""id"": ""7287087200"",
""sequence_id"": ""0"",
""etag"": ""0"",
""sha1"": ""0bbd79a105c504f99573e3799756debba4c760cd"",
""name"": ""box-logo.png""
},
""due_at"": ""2014-04-03T11:09:43-07:00"",
""action"": ""review"",
""message"": ""REVIEW PLZ K THX"",
""task_assignment_collection"": {
""total_count"": 0,
""entries"": []
},
""is_completed"": false,
""created_by"": {
""type"": ""user"",
""id"": ""11993747"",
""name"": ""sean"",
""login"": ""sean@box.com""
},
""created_at"": ""2013-04-03T11:12:54-07:00"",
""completion_rule"": ""any_assignee""
}";
IBoxRequest boxRequest = null;
Uri tasksUri = new Uri(Constants.TasksEndpointString);
Config.SetupGet(x => x.TasksEndpointUri).Returns(tasksUri);
Handler.Setup(h => h.ExecuteAsync<BoxTask>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxTask>>(new BoxResponse<BoxTask>()
{
Status = ResponseStatus.Success,
ContentString = responseString
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxTaskCreateRequest taskCreateRequest = new BoxTaskCreateRequest()
{
Item = new BoxRequestEntity()
{
Id = "7287087200",
Type = BoxType.file
},
Message = "REVIEW PLZ K THX",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

CompletionRule = BoxCompletionRule.any_assignee
};
BoxTask result = await _tasksManager.CreateTaskAsync(taskCreateRequest);

/*** Assert ***/
//Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(tasksUri, boxRequest.AbsoluteUri.AbsoluteUri);
BoxTaskCreateRequest payload = JsonConvert.DeserializeObject<BoxTaskCreateRequest>(boxRequest.Payload);
Assert.AreEqual(taskCreateRequest.Item.Id, payload.Item.Id);
Assert.AreEqual(taskCreateRequest.Item.Type, payload.Item.Type);
Assert.AreEqual(taskCreateRequest.Message, payload.Message);
Assert.AreEqual(taskCreateRequest.CompletionRule, payload.CompletionRule);

//Response check
Assert.AreEqual(BoxCompletionRule.any_assignee, result.CompletionRule);
}

[TestMethod]
Expand Down
15 changes: 15 additions & 0 deletions Box.V2/Models/BoxEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,19 @@ public enum DispositionAction
permanently_delete,
remove_retention
}

/// <summary>
/// Defines which assignees need to complete the task before it is considered completed.
/// </summary>
public enum BoxCompletionRule
{
/// <summary>
/// all_assignees requires all assignees to review or approve the the task in order for it to be considered completed.
/// </summary>
all_assignees,
/// <summary>
/// any_assignee accepts any one assignee to review or approve the the task in order for it to be considered completed.
/// </summary>
any_assignee
}
}
9 changes: 8 additions & 1 deletion Box.V2/Models/BoxTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class BoxTask : BoxEntity
public const string FieldIsCompleted = "is_completed";
public const string FieldCreatedBy = "created_by";
public const string FieldTaskAssignmentCollection = "task_assignment_collection";

public const string FieldCompletionRule = "completion_rule";

/// <summary>
/// Date of task completion
/// </summary>
Expand Down Expand Up @@ -53,5 +54,11 @@ public class BoxTask : BoxEntity
/// </summary>
[JsonProperty(PropertyName = FieldTaskAssignmentCollection)]
public virtual BoxCollection<BoxTaskAssignment> TaskAssignments { get; private set; }

/// <summary>
/// Gets value indicating which assignees need to complete this task before the task is considered completed.
/// </summary>
[JsonProperty(PropertyName = FieldCompletionRule)]
public virtual BoxCompletionRule CompletionRule { get; private set; }
}
}
6 changes: 6 additions & 0 deletions Box.V2/Models/Request/BoxTaskCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ public string Action
/// </summary>
[JsonProperty(PropertyName = "due_at")]
public DateTimeOffset? DueAt { get; set; }

/// <summary>
/// Defines which assignees need to complete this task before the task is considered completed.
/// </summary>
[JsonProperty(PropertyName = "completion_rule")]
public BoxCompletionRule? CompletionRule { get; set; }
}
}