Skip to content

Commit

Permalink
Added support for Task completion_rule field (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
antusus authored Oct 13, 2021
1 parent a210952 commit 5ac133d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
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);

//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",
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; }
}
}

0 comments on commit 5ac133d

Please sign in to comment.