Skip to content

Commit e389a33

Browse files
committed
Add tests
1 parent 2fc7cb4 commit e389a33

File tree

7 files changed

+157
-7
lines changed

7 files changed

+157
-7
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org).
88
### Added
99
- Resend Invite feature [#153](https://github.com/signnow/SignNow.NET/issues/153)
1010
- Options for Embedded invite [#160](https://github.com/signnow/SignNow.NET/issues/160)
11+
- DocumentGroup feature [#161](https://github.com/signnow/SignNow.NET/issues/161)
1112

1213
### Changed
1314
- `DownloadDocumentResponse` model extended with `MediaType` property

Diff for: SignNow.Net.Test/AssertExtensions.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ private static string PrettifyJson(string json)
3939
using var stringReader = new StringReader(json);
4040
using var stringWriter = new StringWriter();
4141
using var jsonReader = new JsonTextReader(stringReader);
42-
using var jsonWriter = new JsonTextWriter(stringWriter)
43-
{
44-
Formatting = Formatting.Indented
45-
};
42+
using var jsonWriter = new JsonTextWriter(stringWriter);
43+
jsonWriter.Formatting = Formatting.Indented;
4644
jsonWriter.WriteToken(jsonReader);
4745

4846
return stringWriter.ToString();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using SignNow.Net.Internal.Helpers.Converters;
3+
using SignNow.Net.Model.Requests.DocumentGroup;
4+
5+
namespace UnitTests.Requests
6+
{
7+
[TestClass]
8+
public class CopyDocumentGroupRequestTest
9+
{
10+
[TestMethod]
11+
public void ShouldBeSerializedAsWithDefaultTimestampTest()
12+
{
13+
var request = new CopyDocumentGroupRequest
14+
{
15+
DocumentGroupName = "test name"
16+
};
17+
var actualTime = UnixTimeStampConverter.ToUnixTimestamp(request.ClientTimestamp);
18+
19+
var expectedJson = $@"{{""document_group_name"":""test name"",""client_timestamp"":""{actualTime}""}}";
20+
21+
Assert.That.JsonEqual(expectedJson, request);
22+
}
23+
}
24+
}

Diff for: SignNow.Net.Test/UnitTests/Services/DocumentGroupServiceTest.cs

+78
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,83 @@ public async Task ThrowsExceptionForWrongParamsClassTest()
7070
StringAssert.Contains(instanceException.Message, "Query params does not have 'limit' and 'offset' options. Use \"LimitOffsetOptions\" class.");
7171
Assert.AreEqual("options", instanceException.ParamName);
7272
}
73+
74+
[TestMethod]
75+
public async Task GetDocumentGroupInfoAsyncTest()
76+
{
77+
var jsonResponse = @"{
78+
""data"": {
79+
""id"": ""03c74b3083f34ebf8ef40a3039dfb32c85a08437"",
80+
""name"": ""CreateDocumentGroupTest"",
81+
""created"": 1729535107,
82+
""updated"": 1729535107,
83+
""invite_id"": null,
84+
""pending_step_id"": null,
85+
""state"": ""created"",
86+
""sign_as_merged"": null,
87+
""last_invite_id"": null,
88+
""owner_email"": ""[email protected]"",
89+
""folder_id"": ""e1d8d63ba51c4009ab8241f279c908a0fd5a5e48"",
90+
""share_info"": {
91+
""is_team_shared"": false,
92+
""role"": ""owner"",
93+
""is_personally_shared_to_others"": false
94+
},
95+
""documents"": [
96+
{
97+
""roles"": [],
98+
""document_name"": ""ForDocumentGroupFile-1"",
99+
""page_count"": 1,
100+
""id"": ""66974a4b421546a69167ba342d1ae94af56ce351"",
101+
""updated"": 1729535105,
102+
""folder_id"": ""e1d8d63ba51c4009ab8241f279c908a0fd5a5e48"",
103+
""owner"": {
104+
""id"": ""40204b3344984733bb16d61f8550f8b5edfd719a"",
105+
""email"": ""[email protected]""
106+
},
107+
""thumbnail"": {
108+
""small"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce351/thumbnail?size=small"",
109+
""medium"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce351/thumbnail?size=medium"",
110+
""large"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce351/thumbnail?size=large""
111+
},
112+
""origin_document_id"": null,
113+
""has_unassigned_field"": false,
114+
""has_credit_card_number"": false,
115+
""field_invites"": [],
116+
""shared_with_team"": null,
117+
""settings"": [],
118+
""allow_to_remove"": true
119+
}
120+
],
121+
""owner"": {
122+
""id"": ""40204b3344984733bb16d61f8550f8b5edfd719a"",
123+
""email"": ""[email protected]"",
124+
""organization"": {
125+
""id"": ""1ef2dc3eef1c2222a8aea48d238968402abc745f""
126+
}
127+
},
128+
""cc_emails"": [],
129+
""freeform_invite"": {
130+
""id"": null,
131+
""last_id"": null
132+
},
133+
""mail_provider"": null
134+
}
135+
}";
136+
var service = new DocumentGroupService(ApiBaseUrl, new Token(),
137+
SignNowClientMock(jsonResponse));
138+
139+
var response = await service.GetDocumentGroupInfoAsync("03c74b3083f34ebf8ef40a3039dfb32c85a08437").ConfigureAwait(false);
140+
141+
Assert.IsInstanceOfType(response, typeof(DocumentGroupInfoResponse));
142+
Assert.AreEqual("03c74b3083f34ebf8ef40a3039dfb32c85a08437", response.Data.Id);
143+
Assert.AreEqual("CreateDocumentGroupTest", response.Data.Name);
144+
Assert.AreEqual("created", response.Data.State);
145+
Assert.AreEqual("e1d8d63ba51c4009ab8241f279c908a0fd5a5e48", response.Data.FolderId);
146+
Assert.AreEqual(1, response.Data.Documents.Count);
147+
Assert.AreEqual("66974a4b421546a69167ba342d1ae94af56ce351", response.Data.Documents[0].Id);
148+
Assert.AreEqual("ForDocumentGroupFile-1", response.Data.Documents[0].Name);
149+
Assert.AreEqual("40204b3344984733bb16d61f8550f8b5edfd719a", response.Data.Owner.Id);
150+
}
73151
}
74152
}

Diff for: SignNow.Net/Interfaces/IDocumentGroup.cs

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public interface IDocumentGroup
6060
/// <returns></returns>
6161
Task MoveDocumentGroupAsync(string documentGroupId, string folderId, bool withSharedDocuments = false, CancellationToken cancellationToken = default);
6262

63+
/// <summary>
64+
/// Copy a document group in any status and set a new name to it.
65+
/// </summary>
66+
/// <param name="documentGroupId">ID of the Document Group.</param>
67+
/// <param name="newName">The name of the new document group copy.</param>
68+
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
69+
/// <returns></returns>
70+
Task CopyDocumentGroupAsync(string documentGroupId, string newName, CancellationToken cancellationToken = default);
71+
6372
/// <summary>
6473
/// Deletes a document group. Documents within the group are not deleted. Document groups cannot be deleted while they have a group invite pending.
6574
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using SignNow.Net.Internal.Helpers.Converters;
4+
5+
namespace SignNow.Net.Model.Requests.DocumentGroup
6+
{
7+
public class CopyDocumentGroupRequest : JsonHttpContent
8+
{
9+
/// <summary>
10+
/// The name of the new document group copy.
11+
/// </summary>
12+
[JsonProperty("document_group_name")]
13+
public string DocumentGroupName { get; set; }
14+
15+
/// <summary>
16+
/// Timestamp document was created.
17+
/// </summary>
18+
[JsonProperty("client_timestamp")]
19+
[JsonConverter(typeof(UnixTimeStampJsonConverter))]
20+
public DateTime ClientTimestamp { get; set; } = DateTime.UtcNow;
21+
}
22+
}

Diff for: SignNow.Net/Service/DocumentGroupService.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task RenameDocumentGroupAsync(string newName, string documentGroupI
108108
};
109109

110110
await SignNowClient
111-
.RequestAsync<DocumentGroupsResponse>(requestOptions, cancellationToken)
111+
.RequestAsync(requestOptions, cancellationToken)
112112
.ConfigureAwait(false);
113113
}
114114

@@ -126,7 +126,25 @@ public async Task MoveDocumentGroupAsync(string documentGroupId, string folderId
126126
};
127127

128128
await SignNowClient
129-
.RequestAsync<DocumentGroupsResponse>(requestOptions, cancellationToken)
129+
.RequestAsync(requestOptions, cancellationToken)
130+
.ConfigureAwait(false);
131+
}
132+
133+
/// <inheritdoc />
134+
/// <exception cref="System.ArgumentException">If document group identity is not valid.</exception>
135+
public async Task CopyDocumentGroupAsync(string documentGroupId, string newName, CancellationToken cancellationToken = default)
136+
{
137+
Token.TokenType = TokenType.Bearer;
138+
139+
var requestOptions = new PostHttpRequestOptions
140+
{
141+
RequestUrl = new Uri(ApiBaseUrl, $"/v2/document-groups/{documentGroupId.ValidateId()}/copy"),
142+
Content = new CopyDocumentGroupRequest { DocumentGroupName = newName },
143+
Token = Token
144+
};
145+
146+
await SignNowClient
147+
.RequestAsync(requestOptions, cancellationToken)
130148
.ConfigureAwait(false);
131149
}
132150

@@ -143,7 +161,7 @@ public async Task DeleteDocumentGroupAsync(string documentGroupId, CancellationT
143161
};
144162

145163
await SignNowClient
146-
.RequestAsync<DocumentGroupsResponse>(requestOptions, cancellationToken)
164+
.RequestAsync(requestOptions, cancellationToken)
147165
.ConfigureAwait(false);
148166
}
149167

0 commit comments

Comments
 (0)