Skip to content

Commit

Permalink
feat: Support Sign Templates and new Sign Request statuses (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 authored Sep 7, 2023
1 parent 3d7278a commit 78580fb
Show file tree
Hide file tree
Showing 27 changed files with 990 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<None Update="Fixtures\BoxSignRequest\GetSignRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignTemplate\GetAllSignTemplates200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignTemplate\GetSignTemplate200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxUsers\AddOrUpdateUserAvatar200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 2 additions & 0 deletions Box.V2.Test/BoxResourceManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected BoxResourceManagerTest()
Config.SetupGet(x => x.FolderLocksEndpointUri).Returns(FolderLocksUri);
Config.SetupGet(x => x.SignRequestsEndpointUri).Returns(SignRequestUri);
Config.SetupGet(x => x.SignRequestsEndpointWithPathUri).Returns(SignRequestWithPathUri);
Config.SetupGet(x => x.SignTemplatesEndpointUri).Returns(new Uri(Constants.SignTemplatesEndpointString));
Config.SetupGet(x => x.SignTemplatesEndpointWithPathUri).Returns(new Uri(Constants.SignTemplatesWithPathEndpointString));
Config.SetupGet(x => x.FileRequestsEndpointWithPathUri).Returns(FileRequestsWithPathUri);
Config.SetupGet(x => x.RetryStrategy).Returns(new InstantRetryStrategy());

Expand Down
4 changes: 3 additions & 1 deletion Box.V2.Test/BoxSignRequestsManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public async Task CreateSignRequest_OptionalParams_Success()
"1234",
"text"
)
}
},
TemplateId = "12345"
};

/*** Act ***/
Expand Down Expand Up @@ -180,6 +181,7 @@ public async Task CreateSignRequest_OptionalParams_Success()
Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.PrefillTags[0].DateValue);
Assert.AreEqual("https://box.com/redirect_url", response.RedirectUrl.ToString());
Assert.AreEqual("https://box.com/declined_redirect_url", response.DeclinedRedirectUrl.ToString());
Assert.AreEqual("12345", response.TemplateId);
}

[TestMethod]
Expand Down
85 changes: 85 additions & 0 deletions Box.V2.Test/BoxSignTemplateManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Box.V2.Test.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json.Linq;

namespace Box.V2.Test
{
[TestClass]
public class BoxSignTemplatesManagerTest : BoxResourceManagerTest
{
private readonly BoxSignTemplatesManager _signTemplatesManager;

public BoxSignTemplatesManagerTest()
{
_signTemplatesManager = new BoxSignTemplatesManager(Config.Object, Service, Converter, AuthRepository);
}

[TestMethod]
public async Task GetSignTemplateById_Success()
{
/** Arrange **/
const string signTemplateId = "93153068-5420-467b-b8ef-8e54bfb7be42";
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignTemplate>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignTemplate>>(new BoxResponse<BoxSignTemplate>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignTemplate/GetSignTemplate200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxSignTemplate response = await _signTemplatesManager.GetSignTemplateByIdAsync(signTemplateId);

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_templates/93153068-5420-467b-b8ef-8e54bfb7be42"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(signTemplateId, response.Id);
Assert.AreEqual("requirements-dev.pdf", response.Name);
Assert.AreEqual("Please sign this document.\n\nKind regards", response.EmailMessage);
Assert.AreEqual("Someone ([email protected]) has requested your signature on a document", response.EmailSubject);
Assert.AreEqual("1234567890", response.ParentFolder.Id);
Assert.AreEqual(1, response.SourceFiles.Count);
Assert.AreEqual("1234567890", response.SourceFiles[0].Id);
Assert.AreEqual("https://app.box.com/sign/ready-sign-link/59917816-c12b-4ef6-8f1d-aaaaaaa", response.ReadySignLink.Url);
}

[TestMethod]
public async Task GetSignTemplates_Success()
{
/** Arrange **/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxCollectionMarkerBased<BoxSignTemplate>>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxCollectionMarkerBased<BoxSignTemplate>>>(new BoxResponse<BoxCollectionMarkerBased<BoxSignTemplate>>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignTemplate/GetAllSignTemplates200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxCollectionMarkerBased<BoxSignTemplate> response = await _signTemplatesManager.GetSignTemplatesAsync(1000, "JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii");

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_templates?limit=1000&marker=JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.Entries.Count);
Assert.AreEqual("93153068-5420-467b-b8ef-8e54bfb7be42", response.Entries[0].Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
}
}
],
"status": "cancelled"
"status": "cancelled",
"template_id": "12345"
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
}
}
],
"status": "converting"
"status": "converting",
"template_id": "12345"
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
],
"is_ready_for_download": true
},
"auto_expire_at": "2021-04-26T08:12:13.982Z"
"auto_expire_at": "2021-04-26T08:12:13.982Z",
"template_id": "12345"
}
]
}
3 changes: 2 additions & 1 deletion Box.V2.Test/Fixtures/BoxSignRequest/GetSignRequest200.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
}
}
],
"status": "converting"
"status": "converting",
"template_id": "12345"
}
101 changes: 101 additions & 0 deletions Box.V2.Test/Fixtures/BoxSignTemplate/GetAllSignTemplates200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"limit": 10,
"next_marker": null,
"prev_marker": null,
"entries": [
{
"id": "93153068-5420-467b-b8ef-8e54bfb7be42",
"type": "sign-template",
"name": "requirements-dev.pdf",
"email_message": "Please sign this document.\n\nKind regards",
"email_subject": "Someone ([email protected]) has requested your signature on a document",
"parent_folder": {
"id": "1234567890",
"etag": "0",
"type": "folder",
"sequence_id": "0",
"name": "My Sign Requests"
},
"auto_expire_days": null,
"source_files": [
{
"id": "1234567890",
"etag": "0",
"type": "file",
"sequence_id": "0",
"sha1": "082c9540e82e9c465309367a3240405aaaaaaa",
"file_version": {
"id": "1234567890",
"type": "file_version",
"sha1": "082c9540e82e9c465309367a3240405aaaaaaa"
}
}
],
"are_email_settings_locked": false,
"are_fields_locked": false,
"are_files_locked": false,
"are_options_locked": false,
"are_recipients_locked": false,
"signers": [
{
"email": "",
"label": "",
"public_id": "18K8K7Q4",
"role": "final_copy_reader",
"is_in_person": false,
"order": 1,
"inputs": []
},
{
"email": "",
"label": "",
"public_id": "13XQXJZ4",
"role": "signer",
"is_in_person": false,
"order": 1,
"inputs": [
{
"document_tag_id": null,
"id": "0260f921-3b52-477f-ae74-aaaaaaa",
"type": "signature",
"text_value": null,
"is_required": true,
"coordinates": {
"x": 0.27038464059712,
"y": 0.10051756244533624
},
"dimensions": {
"width": 0.23570031566618235,
"height": 0.04781003891921971
},
"date_value": null,
"page_index": 0,
"checkbox_value": null,
"document_id": "2fdf9003-d798-40ee-be7f-aaaaaaa",
"content_type": "signature",
"dropdown_choices": null,
"group_id": null,
"label": null
}
]
}
],
"ready_sign_link": {
"url": "https://app.box.com/sign/ready-sign-link/59917816-c12b-4ef6-8f1d-aaaaaaa",
"name": "requirements-dev.pdf",
"instructions": "Hello",
"folder_id": "1234567890",
"is_notification_disabled": true,
"is_active": true
},
"custom_branding": null,
"days_valid": 0,
"additional_info": {
"non_editable": [],
"required": {
"signers": [["email"], ["email"]]
}
}
}
]
}
102 changes: 102 additions & 0 deletions Box.V2.Test/Fixtures/BoxSignTemplate/GetSignTemplate200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

{
"id": "93153068-5420-467b-b8ef-8e54bfb7be42",
"type": "sign-template",
"name": "requirements-dev.pdf",
"email_message": "Please sign this document.\n\nKind regards",
"email_subject": "Someone ([email protected]) has requested your signature on a document",
"parent_folder": {
"id": "1234567890",
"etag": "0",
"type": "folder",
"sequence_id": "0",
"name": "My Sign Requests"
},
"auto_expire_days": null,
"source_files": [
{
"id": "1234567890",
"etag": "0",
"type": "file",
"sequence_id": "0",
"sha1": "082c9540e82e9c465309367a3240405aaaaaaa",
"file_version": {
"id": "1234567890",
"type": "file_version",
"sha1": "082c9540e82e9c465309367a3240405aaaaaaa"
}
}
],
"are_email_settings_locked": false,
"are_fields_locked": false,
"are_files_locked": false,
"are_options_locked": false,
"are_recipients_locked": false,
"signers": [
{
"email": "",
"label": "",
"public_id": "18K8K7Q4",
"role": "final_copy_reader",
"is_in_person": false,
"order": 1,
"inputs": []
},
{
"email": "",
"label": "",
"public_id": "13XQXJZ4",
"role": "signer",
"is_in_person": false,
"order": 1,
"inputs": [
{
"document_tag_id": null,
"id": "0260f921-3b52-477f-ae74-aaaaaaa",
"type": "signature",
"text_value": null,
"is_required": true,
"coordinates": {
"x": 0.27038464059712,
"y": 0.10051756244533624
},
"dimensions": {
"width": 0.23570031566618235,
"height": 0.04781003891921971
},
"date_value": null,
"page_index": 0,
"checkbox_value": null,
"document_id": "2fdf9003-d798-40ee-be7f-aaaaaaa",
"content_type": "signature",
"dropdown_choices": null,
"group_id": null,
"label": null
}
]
}
],
"ready_sign_link": {
"url": "https://app.box.com/sign/ready-sign-link/59917816-c12b-4ef6-8f1d-aaaaaaa",
"name": "requirements-dev.pdf",
"instructions": "Hello",
"folder_id": "1234567890",
"is_notification_disabled": true,
"is_active": true
},
"custom_branding": null,
"days_valid": 0,
"additional_info": {
"non_editable": [],
"required": {
"signers": [
[
"email"
],
[
"email"
]
]
}
}
}
7 changes: 7 additions & 0 deletions Box.V2/Box.V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="Managers\BoxRetentionPoliciesManager.cs" />
<Compile Include="Managers\BoxSharedItemsManager.cs" />
<Compile Include="Managers\BoxSignRequestsManager.cs" />
<Compile Include="Managers\BoxSignTemplatesManager.cs" />
<Compile Include="Managers\BoxStoragePoliciesManager.cs" />
<Compile Include="Managers\BoxTasksManager.cs" />
<Compile Include="Managers\BoxTermsOfServiceManager.cs" />
Expand All @@ -127,6 +128,7 @@
<Compile Include="Managers\IBoxSearchManager.cs" />
<Compile Include="Managers\IBoxSharedItemsManager.cs" />
<Compile Include="Managers\IBoxSignRequestsManager.cs" />
<Compile Include="Managers\IBoxSignTemplatesManager.cs" />
<Compile Include="Managers\IBoxStoragePoliciesManager.cs" />
<Compile Include="Managers\IBoxTasksManager.cs" />
<Compile Include="Managers\IBoxTermsOfServiceManager.cs" />
Expand Down Expand Up @@ -182,6 +184,11 @@
<Compile Include="Models\BoxSignRequestPrefillTag.cs" />
<Compile Include="Models\BoxSignRequestSigner.cs" />
<Compile Include="Models\BoxSignRequestSignFiles.cs" />
<Compile Include="Models\BoxSignTemplate.cs" />
<Compile Include="Models\BoxSignTemplateAdditionalInfo.cs" />
<Compile Include="Models\BoxSignTemplateCustomBranding.cs" />
<Compile Include="Models\BoxSignTemplateReadySignLink.cs" />
<Compile Include="Models\BoxSignTemplateSigner.cs" />
<Compile Include="Models\BoxStoragePolicy.cs" />
<Compile Include="Models\BoxStoragePolicyAssignment.cs" />
<Compile Include="Models\BoxTask.cs" />
Expand Down
Loading

0 comments on commit 78580fb

Please sign in to comment.