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

feat: add BoxSign API support #765

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
<None Update="Fixtures\BoxSignRequest\CancelSignRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignRequest\CreateSignRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignRequest\GetAllSignRequests200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignRequest\GetSignRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\smalltest.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
11 changes: 11 additions & 0 deletions Box.V2.Test/BoxResourceManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reflection;
using System.Text;
using Box.V2.Auth;
Expand Down Expand Up @@ -27,6 +28,8 @@ public abstract class BoxResourceManagerTest
protected Uri UserUri = new Uri(Constants.UserEndpointString);
protected Uri InviteUri = new Uri(Constants.BoxApiUriString + Constants.InviteString);
protected Uri FolderLocksUri = new Uri(Constants.FolderLocksEndpointString);
protected Uri SignRequestUri = new Uri(Constants.SignRequestsEndpointString);
protected Uri SignRequestWithPathUri = new Uri(Constants.SignRequestsWithPathEndpointString);

protected BoxResourceManagerTest()
{
Expand All @@ -43,6 +46,8 @@ protected BoxResourceManagerTest()
Config.SetupGet(x => x.UserEndpointUri).Returns(UserUri);
Config.SetupGet(x => x.InviteEndpointUri).Returns(InviteUri);
Config.SetupGet(x => x.FolderLocksEndpointUri).Returns(FolderLocksUri);
Config.SetupGet(x => x.SignRequestsEndpointUri).Returns(SignRequestUri);
Config.SetupGet(x => x.SignRequestsEndpointWithPathUri).Returns(SignRequestWithPathUri);

AuthRepository = new AuthRepository(Config.Object, Service, Converter, new OAuthSession("fakeAccessToken", "fakeRefreshToken", 3600, "bearer"));
}
Expand Down Expand Up @@ -80,5 +85,11 @@ public static T CreateInstanceNonPublicConstructor<T>()
System.Threading.Thread.CurrentThread.CurrentCulture);
return inst;
}

public string LoadFixtureFromJson(string path)
{
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
return File.ReadAllText(filePath);
}
}
}
308 changes: 308 additions & 0 deletions Box.V2.Test/BoxSignRequestsManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Box.V2.Test
{
[TestClass]
public class BoxSignRequestsManagerTest : BoxResourceManagerTest
{
private readonly BoxSignRequestsManager _signRequestsManager;

public BoxSignRequestsManagerTest()
{
_signRequestsManager = new BoxSignRequestsManager(Config.Object, Service, Converter, AuthRepository);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task CreateSignRequest_RequiredParams_Success()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignRequest>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignRequest>>(new BoxResponse<BoxSignRequest>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/CreateSignRequest200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r); ;

var sourceFiles = new List<BoxSignRequestCreateSourceFile>
{
new BoxSignRequestCreateSourceFile()
{
Id = "12345"
}
};

var signers = new List<BoxSignRequestSignerCreate>
{
new BoxSignRequestSignerCreate()
{
Email = "[email protected]"
}
};

var parentFolder = new BoxRequestEntity()
{
Id = "12345",
Type = BoxType.folder
};

var request = new BoxSignRequestCreateRequest
{
SourceFiles = sourceFiles,
Signers = signers,
ParentFolder = parentFolder,
};

/*** Act ***/
var response = await _signRequestsManager.CreateSignRequestAsync(request);

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.SourceFiles.Count);
Assert.AreEqual("12345", response.SourceFiles[0].Id);
Assert.AreEqual(1, response.Signers.Count);
Assert.AreEqual("[email protected]", response.Signers[0].Email);
Assert.AreEqual("12345", response.ParentFolder.Id);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task CreateSignRequest_OptionalParams_Success()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignRequest>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignRequest>>(new BoxResponse<BoxSignRequest>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/CreateSignRequest200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r); ;

var sourceFiles = new List<BoxSignRequestCreateSourceFile>
{
new BoxSignRequestCreateSourceFile()
{
Id = "12345"
}
};

var signers = new List<BoxSignRequestSignerCreate>
{
new BoxSignRequestSignerCreate()
{
Email = "[email protected]"
}
};

var parentFolder = new BoxRequestEntity()
{
Id = "12345",
Type = BoxType.folder
};

var request = new BoxSignRequestCreateRequest
{
IsDocumentPreparationNeeded = true,
AreRemindersEnabled = true,
AreTextSignaturesEnabled = true,
DaysValid = 2,
EmailMessage = "Hello! Please sign the document below",
EmailSubject = "Sign Request from Acme",
ExternalId = "123",
SourceFiles = sourceFiles,
Signers = signers,
ParentFolder = parentFolder,
PrefillTags = new List<BoxSignRequestPrefillTag>
{
new BoxSignRequestPrefillTag
{
DocumentTagId = "1234",
TextValue = "text",
CheckboxValue = true,
DateValue = DateTimeOffset.Parse("2021-04-26T08:12:13.982Z")
}
}
};

/*** Act ***/
var response = await _signRequestsManager.CreateSignRequestAsync(request);

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.SourceFiles.Count);
Assert.AreEqual("12345", response.SourceFiles[0].Id);
Assert.AreEqual(1, response.Signers.Count);
Assert.AreEqual("[email protected]", response.Signers[0].Email);
Assert.AreEqual("12345", response.ParentFolder.Id);
Assert.IsTrue(response.IsDocumentPreparationNeeded);
Assert.IsTrue(response.AreRemindersEnabled);
Assert.IsTrue(response.AreTextSignaturesEnabled);
Assert.AreEqual(2, response.DaysValid);
Assert.AreEqual("Hello! Please sign the document below", response.EmailMessage);
Assert.AreEqual("Sign Request from Acme", response.EmailSubject);
Assert.AreEqual("123", response.ExternalId);
Assert.AreEqual(1, response.PrefillTags.Count);
Assert.AreEqual("1234", response.PrefillTags[0].DocumentTagId);
Assert.AreEqual("text", response.PrefillTags[0].TextValue);
Assert.IsTrue(response.PrefillTags[0].CheckboxValue.Value);
Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.PrefillTags[0].DateValue);
}

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

/*** Act ***/
BoxCollectionMarkerBased<BoxSignRequest> response = await _signRequestsManager.GetSignRequestsAsync(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_requests?limit=1000&marker=JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.Entries[0].SourceFiles.Count);
Assert.AreEqual("12345", response.Entries[0].SourceFiles[0].Id);
Assert.AreEqual(1, response.Entries[0].Signers.Count);
Assert.AreEqual("[email protected]", response.Entries[0].Signers[0].Email);
Assert.AreEqual("12345", response.Entries[0].ParentFolder.Id);
Assert.IsTrue(response.Entries[0].IsDocumentPreparationNeeded);
Assert.IsTrue(response.Entries[0].AreRemindersEnabled);
Assert.IsTrue(response.Entries[0].AreTextSignaturesEnabled);
Assert.AreEqual(2, response.Entries[0].DaysValid);
Assert.AreEqual("Hello! Please sign the document below", response.Entries[0].EmailMessage);
Assert.AreEqual("Sign Request from Acme", response.Entries[0].EmailSubject);
Assert.AreEqual("123", response.Entries[0].ExternalId);
Assert.AreEqual(1, response.Entries[0].PrefillTags.Count);
Assert.AreEqual("1234", response.Entries[0].PrefillTags[0].DocumentTagId);
Assert.AreEqual("text", response.Entries[0].PrefillTags[0].TextValue);
Assert.IsTrue(response.Entries[0].PrefillTags[0].CheckboxValue.Value);
Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.Entries[0].PrefillTags[0].DateValue);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task GetSignRequestById_Success()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignRequest>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignRequest>>(new BoxResponse<BoxSignRequest>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/GetSignRequest200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxSignRequest response = await _signRequestsManager.GetSignRequestByIdAsync("12345");

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests/12345"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.SourceFiles.Count);
Assert.AreEqual("12345", response.SourceFiles[0].Id);
Assert.AreEqual(1, response.Signers.Count);
Assert.AreEqual("[email protected]", response.Signers[0].Email);
Assert.AreEqual("12345", response.ParentFolder.Id);
Assert.IsTrue(response.IsDocumentPreparationNeeded);
Assert.IsTrue(response.AreRemindersEnabled);
Assert.IsTrue(response.AreTextSignaturesEnabled);
Assert.AreEqual(2, response.DaysValid);
Assert.AreEqual("Hello! Please sign the document below", response.EmailMessage);
Assert.AreEqual("Sign Request from Acme", response.EmailSubject);
Assert.AreEqual("123", response.ExternalId);
Assert.AreEqual(1, response.PrefillTags.Count);
Assert.AreEqual("1234", response.PrefillTags[0].DocumentTagId);
Assert.AreEqual("text", response.PrefillTags[0].TextValue);
Assert.IsTrue(response.PrefillTags[0].CheckboxValue.Value);
Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.PrefillTags[0].DateValue);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task CancelSignRequest_Success()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignRequest>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignRequest>>(new BoxResponse<BoxSignRequest>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/CancelSignRequest200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxSignRequest response = await _signRequestsManager.CancelSignRequestAsync("12345");

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests/12345/cancel"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual("12345", response.Id);
Assert.AreEqual(BoxSignRequest.BoxSignRequestStatus.cancelled, response.Status);
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task ResendSignRequest_Success()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<object>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<object>>(new BoxResponse<object>()
{
Status = ResponseStatus.Success,
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
await _signRequestsManager.ResendSignRequestAsync("12345");

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests/12345/resend"), boxRequest.AbsoluteUri);
}
}
}
Loading