|
6 | 6 | using SignhostAPIClient.Tests.JSON; |
7 | 7 | using Xunit; |
8 | 8 |
|
9 | | -namespace Signhost.APIClient.Rest.Tests |
| 9 | +namespace Signhost.APIClient.Rest.Tests; |
| 10 | + |
| 11 | +public class PostbackTests |
10 | 12 | { |
11 | | - public class PostbackTests |
| 13 | + [Fact] |
| 14 | + public void PostbackTransaction_should_get_serialized_correctly() |
12 | 15 | { |
13 | | - [Fact] |
14 | | - public void PostbackTransaction_should_get_serialized_correctly() |
15 | | - { |
16 | | - string json = JsonResources.MockPostbackValid; |
17 | | - var postbackTransaction = JsonSerializer.Deserialize<PostbackTransaction>(json, SignhostJsonSerializerOptions.Default); |
18 | | - |
19 | | - postbackTransaction.Id .Should().Be("b10ae331-af78-4e79-a39e-5b64693b6b68"); |
20 | | - postbackTransaction.Status .Should().Be(TransactionStatus.InProgress); |
21 | | - postbackTransaction.Seal .Should().BeTrue(); |
22 | | - postbackTransaction.Reference .Should().Be("Contract #123"); |
23 | | - postbackTransaction.PostbackUrl .Should().Be("https://example.com/postback.php"); |
24 | | - postbackTransaction.SignRequestMode .Should().Be(2); |
25 | | - postbackTransaction.DaysToExpire .Should().Be(30); |
26 | | - postbackTransaction.SendEmailNotifications.Should().BeTrue(); |
27 | | - postbackTransaction.CreatedDateTime .Should().Be(DateTimeOffset.Parse("2016-08-31T21:22:56.2467731+02:00")); |
28 | | - postbackTransaction.CanceledDateTime .Should().BeNull(); |
29 | | - (postbackTransaction.Context is null) .Should().BeTrue(); |
30 | | - postbackTransaction.Checksum .Should().Be("cdc09eee2ed6df2846dcc193aedfef59f2834f8d"); |
31 | | - |
32 | | - var signers = postbackTransaction.Signers; |
33 | | - signers.Should().HaveCount(1); |
34 | | - |
35 | | - var signer = signers.Single(); |
36 | | - signer.Id .Should().Be("fa95495d-6c59-48e0-962a-a4552f8d6b85"); |
37 | | - signer.Expires .Should().BeNull(); |
38 | | - signer.Email .Should().Be("user@example.com"); |
39 | | - signer.SendSignRequest .Should().BeTrue(); |
40 | | - signer.SendSignConfirmation.Should().BeNull(); |
41 | | - signer.SignRequestMessage .Should().Be("Hello, could you please sign this document? Best regards, John Doe"); |
42 | | - signer.DaysToRemind .Should().Be(15); |
43 | | - signer.Language .Should().Be("en-US"); |
44 | | - signer.ScribbleName .Should().Be("John Doe"); |
45 | | - signer.ScribbleNameFixed .Should().BeFalse(); |
46 | | - signer.Reference .Should().Be("Client #123"); |
47 | | - signer.ReturnUrl .Should().Be("https://signhost.com"); |
48 | | - signer.RejectReason .Should().BeNull(); |
49 | | - signer.SignUrl .Should().Be("https://view.signhost.com/sign/d3c93bd6-f1ce-48e7-8c9c-c2babfdd4034"); |
50 | | - (signer.Context is null) .Should().BeTrue(); |
51 | | - |
52 | | - var verifications = signer.Verifications; |
53 | | - verifications.Should().HaveCount(3); |
54 | | - |
55 | | - var phoneNumberVerification = verifications[0] as PhoneNumberVerification; |
56 | | - phoneNumberVerification .Should().NotBeNull(); |
57 | | - phoneNumberVerification.Number.Should().Be("+31612345678"); |
58 | | - |
59 | | - var scribbleVerification = verifications[1] as ScribbleVerification; |
60 | | - scribbleVerification .Should().NotBeNull(); |
61 | | - scribbleVerification.RequireHandsignature.Should().BeFalse(); |
62 | | - scribbleVerification.ScribbleNameFixed .Should().BeFalse(); |
63 | | - scribbleVerification.ScribbleName .Should().Be("John Doe"); |
64 | | - |
65 | | - var ipAddressVerification = verifications[2] as IPAddressVerification; |
66 | | - ipAddressVerification .Should().NotBeNull(); |
67 | | - ipAddressVerification.IPAddress.Should().Be("1.2.3.4"); |
68 | | - |
69 | | - var activities = signer.Activities; |
70 | | - activities.Should().HaveCount(3); |
71 | | - |
72 | | - var openedActivity = activities[0]; |
73 | | - openedActivity.Id .Should().Be("bcba44a9-c201-4494-9920-2c1f7baebcf0"); |
74 | | - openedActivity.Code .Should().Be(ActivityType.Opened); |
75 | | - openedActivity.Info .Should().BeNull(); |
76 | | - openedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2016-06-15T23:33:04.1965465+02:00")); |
77 | | - |
78 | | - var documentOpenedActivity = activities[1]; |
79 | | - documentOpenedActivity.Id .Should().Be("7aacf96a-5c2f-475d-98a5-726e41bfc5d3"); |
80 | | - documentOpenedActivity.Code .Should().Be(ActivityType.DocumentOpened); |
81 | | - documentOpenedActivity.Info .Should().Be("file1"); |
82 | | - documentOpenedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2020-01-30T16:31:05.6679583+01:00")); |
83 | | - |
84 | | - var signedActivity = activities[2]; |
85 | | - signedActivity.Id .Should().Be("de94cf6e-e1a3-4c33-93bf-2013b036daaf"); |
86 | | - signedActivity.Code .Should().Be(ActivityType.Signed); |
87 | | - signedActivity.Info .Should().BeNull(); |
88 | | - signedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2016-06-15T23:38:04.1965465+02:00")); |
89 | | - |
90 | | - var receivers = postbackTransaction.Receivers; |
91 | | - receivers.Should().HaveCount(1); |
92 | | - |
93 | | - var receiver = receivers.Single(); |
94 | | - receiver.Name .Should().Be("John Doe"); |
95 | | - receiver.Email .Should().Be("user@example.com"); |
96 | | - receiver.Language .Should().Be("en-US"); |
97 | | - receiver.Message .Should().Be("Hello, please find enclosed the digital signed document. Best regards, John Doe"); |
98 | | - receiver.Reference .Should().BeNull(); |
99 | | - receiver.Activities .Should().BeNull(); |
100 | | - (receiver.Context is null).Should().BeTrue(); |
101 | | - |
102 | | - var files = postbackTransaction.Files; |
103 | | - files.Should().HaveCount(1); |
104 | | - |
105 | | - var file = files["file1"]; |
106 | | - file.DisplayName.Should().Be("Sample File"); |
107 | | - |
108 | | - var links = file.Links; |
109 | | - links.Should().HaveCount(1); |
110 | | - |
111 | | - var link = links.Single(); |
112 | | - link.Rel .Should().Be("file"); |
113 | | - link.Type.Should().Be("application/pdf"); |
114 | | - link.Link.Should().Be("https://api.signhost.com/api/transaction/b10ae331-af78-4e79-a39e-5b64693b6b68/file/file1"); |
115 | | - } |
| 16 | + string json = JsonResources.MockPostbackValid; |
| 17 | + var postbackTransaction = JsonSerializer.Deserialize<PostbackTransaction>(json, SignhostJsonSerializerOptions.Default); |
| 18 | + |
| 19 | + postbackTransaction.Id .Should().Be("b10ae331-af78-4e79-a39e-5b64693b6b68"); |
| 20 | + postbackTransaction.Status .Should().Be(TransactionStatus.InProgress); |
| 21 | + postbackTransaction.Seal .Should().BeTrue(); |
| 22 | + postbackTransaction.Reference .Should().Be("Contract #123"); |
| 23 | + postbackTransaction.PostbackUrl .Should().Be("https://example.com/postback.php"); |
| 24 | + postbackTransaction.SignRequestMode .Should().Be(2); |
| 25 | + postbackTransaction.DaysToExpire .Should().Be(30); |
| 26 | + postbackTransaction.SendEmailNotifications.Should().BeTrue(); |
| 27 | + postbackTransaction.CreatedDateTime .Should().Be(DateTimeOffset.Parse("2016-08-31T21:22:56.2467731+02:00")); |
| 28 | + postbackTransaction.CanceledDateTime .Should().BeNull(); |
| 29 | + (postbackTransaction.Context is null) .Should().BeTrue(); |
| 30 | + postbackTransaction.Checksum .Should().Be("cdc09eee2ed6df2846dcc193aedfef59f2834f8d"); |
| 31 | + |
| 32 | + var signers = postbackTransaction.Signers; |
| 33 | + signers.Should().HaveCount(1); |
| 34 | + |
| 35 | + var signer = signers.Single(); |
| 36 | + signer.Id .Should().Be("fa95495d-6c59-48e0-962a-a4552f8d6b85"); |
| 37 | + signer.Expires .Should().BeNull(); |
| 38 | + signer.Email .Should().Be("user@example.com"); |
| 39 | + signer.SendSignRequest .Should().BeTrue(); |
| 40 | + signer.SendSignConfirmation.Should().BeNull(); |
| 41 | + signer.SignRequestMessage .Should().Be("Hello, could you please sign this document? Best regards, John Doe"); |
| 42 | + signer.DaysToRemind .Should().Be(15); |
| 43 | + signer.Language .Should().Be("en-US"); |
| 44 | + signer.ScribbleName .Should().Be("John Doe"); |
| 45 | + signer.ScribbleNameFixed .Should().BeFalse(); |
| 46 | + signer.Reference .Should().Be("Client #123"); |
| 47 | + signer.ReturnUrl .Should().Be("https://signhost.com"); |
| 48 | + signer.RejectReason .Should().BeNull(); |
| 49 | + signer.SignUrl .Should().Be("https://view.signhost.com/sign/d3c93bd6-f1ce-48e7-8c9c-c2babfdd4034"); |
| 50 | + (signer.Context is null) .Should().BeTrue(); |
| 51 | + |
| 52 | + var verifications = signer.Verifications; |
| 53 | + verifications.Should().HaveCount(3); |
| 54 | + |
| 55 | + var phoneNumberVerification = verifications[0] as PhoneNumberVerification; |
| 56 | + phoneNumberVerification .Should().NotBeNull(); |
| 57 | + phoneNumberVerification.Number.Should().Be("+31612345678"); |
| 58 | + |
| 59 | + var scribbleVerification = verifications[1] as ScribbleVerification; |
| 60 | + scribbleVerification .Should().NotBeNull(); |
| 61 | + scribbleVerification.RequireHandsignature.Should().BeFalse(); |
| 62 | + scribbleVerification.ScribbleNameFixed .Should().BeFalse(); |
| 63 | + scribbleVerification.ScribbleName .Should().Be("John Doe"); |
| 64 | + |
| 65 | + var ipAddressVerification = verifications[2] as IPAddressVerification; |
| 66 | + ipAddressVerification .Should().NotBeNull(); |
| 67 | + ipAddressVerification.IPAddress.Should().Be("1.2.3.4"); |
| 68 | + |
| 69 | + var activities = signer.Activities; |
| 70 | + activities.Should().HaveCount(3); |
| 71 | + |
| 72 | + var openedActivity = activities[0]; |
| 73 | + openedActivity.Id .Should().Be("bcba44a9-c201-4494-9920-2c1f7baebcf0"); |
| 74 | + openedActivity.Code .Should().Be(ActivityType.Opened); |
| 75 | + openedActivity.Info .Should().BeNull(); |
| 76 | + openedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2016-06-15T23:33:04.1965465+02:00")); |
| 77 | + |
| 78 | + var documentOpenedActivity = activities[1]; |
| 79 | + documentOpenedActivity.Id .Should().Be("7aacf96a-5c2f-475d-98a5-726e41bfc5d3"); |
| 80 | + documentOpenedActivity.Code .Should().Be(ActivityType.DocumentOpened); |
| 81 | + documentOpenedActivity.Info .Should().Be("file1"); |
| 82 | + documentOpenedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2020-01-30T16:31:05.6679583+01:00")); |
| 83 | + |
| 84 | + var signedActivity = activities[2]; |
| 85 | + signedActivity.Id .Should().Be("de94cf6e-e1a3-4c33-93bf-2013b036daaf"); |
| 86 | + signedActivity.Code .Should().Be(ActivityType.Signed); |
| 87 | + signedActivity.Info .Should().BeNull(); |
| 88 | + signedActivity.CreatedDateTime.Should().Be(DateTimeOffset.Parse("2016-06-15T23:38:04.1965465+02:00")); |
| 89 | + |
| 90 | + var receivers = postbackTransaction.Receivers; |
| 91 | + receivers.Should().HaveCount(1); |
| 92 | + |
| 93 | + var receiver = receivers.Single(); |
| 94 | + receiver.Name .Should().Be("John Doe"); |
| 95 | + receiver.Email .Should().Be("user@example.com"); |
| 96 | + receiver.Language .Should().Be("en-US"); |
| 97 | + receiver.Message .Should().Be("Hello, please find enclosed the digital signed document. Best regards, John Doe"); |
| 98 | + receiver.Reference .Should().BeNull(); |
| 99 | + receiver.Activities .Should().BeNull(); |
| 100 | + (receiver.Context is null).Should().BeTrue(); |
| 101 | + |
| 102 | + var files = postbackTransaction.Files; |
| 103 | + files.Should().HaveCount(1); |
| 104 | + |
| 105 | + var file = files["file1"]; |
| 106 | + file.DisplayName.Should().Be("Sample File"); |
| 107 | + |
| 108 | + var links = file.Links; |
| 109 | + links.Should().HaveCount(1); |
| 110 | + |
| 111 | + var link = links.Single(); |
| 112 | + link.Rel .Should().Be("file"); |
| 113 | + link.Type.Should().Be("application/pdf"); |
| 114 | + link.Link.Should().Be("https://api.signhost.com/api/transaction/b10ae331-af78-4e79-a39e-5b64693b6b68/file/file1"); |
116 | 115 | } |
117 | 116 | } |
0 commit comments