Skip to content

Commit

Permalink
Merge pull request #12 from criipto/mutation-ChangeSignatory
Browse files Browse the repository at this point in the history
add support for ChangeSignatory mutation
  • Loading branch information
sgryt authored Mar 21, 2023
2 parents a5a9d90 + 9f0a55f commit 673fe2c
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 7 deletions.
76 changes: 76 additions & 0 deletions Criipto.Signatures.IntegrationTests/ChangeSignatoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Xunit;
using Criipto.Signatures;
using Criipto.Signatures.Models;
using System.Collections.Generic;
using System.Linq;
namespace Criipto.Signatures.IntegrationTests;

public class ChangeSignatoryTests
{

[Fact]
public async void MutationChangesEvidenceProviders()
{
using (var client = new CriiptoSignaturesClient(Dsl.CLIENT_ID, Dsl.CLIENT_SECRET, "test"))
{
// Arrange
var signatureOrder = await client.CreateSignatureOrder(
new CreateSignatureOrderInput()
{
title = "Title",
expiresInDays = 1,
documents = new List<DocumentInput>(){
new DocumentInput {
pdf =
new PadesDocumentInput
{
title = "TEST",
blob = Dsl.Sample
}
}
},
evidenceProviders = new List<EvidenceProviderInput>() {
new EvidenceProviderInput() {
enabledByDefault = false,
drawable = new DrawableEvidenceProviderInput() {
requireName = true
}
}
}
}
);

var signatory = await client.AddSignatory(
signatureOrder
);

var soDrawable =
signatureOrder!.evidenceProviders
.Where(e => e is DrawableSignatureEvidenceProvider)
.First();

// Act
var actual = await client.ChangeSignatory(
signatory,
new ChangeSignatoryInput()
{
evidenceProviders = new List<SignatoryEvidenceProviderInput>() {
new SignatoryEvidenceProviderInput() {
id = soDrawable.id
}
}
}
);

// Assert
Assert.NotNull(signatory?.id);
Assert.NotNull(signatory?.href);

var drawable =
actual!.evidenceProviders
.Where(e => e is DrawableSignatureEvidenceProvider)
.First();
Assert.NotNull(drawable);
}
}
}
37 changes: 30 additions & 7 deletions Criipto.Signatures/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,12 @@ public async Task<SignatureOrder> CreateSignatureOrder(CreateSignatureOrderInput

public async Task<Signatory> AddSignatory(AddSignatoryInput input)
{
var response = await graphQLClient.SendMutationAsync(
var data = await SendMutation(
AddSignatoryMutation.Request(new { input = input }),
() => new { addSignatory = new AddSignatoryOutput() }
).ConfigureAwait(false);

if (response.Errors?.Length > 0)
{
throw new GraphQLException(response.Errors[0].Message);
}

return response.Data.addSignatory.signatory;
return data.addSignatory.signatory;
}

public async Task<Signatory> AddSignatory(SignatureOrder signatureOrder)
Expand Down Expand Up @@ -142,6 +137,34 @@ public async Task<Signatory> AddSignatory(string signatureOrderId, AddSignatoryI
return await AddSignatory(input).ConfigureAwait(false);
}

public async Task<Signatory> ChangeSignatory(ChangeSignatoryInput input)
{
var data = await SendMutation(
ChangeSignatoryMutation.Request(new { input = input }),
() => new { changeSignatory = new ChangeSignatoryOutput() }
).ConfigureAwait(false);

return data.changeSignatory.signatory;
}

public async Task<Signatory> ChangeSignatory(Signatory signatory, ChangeSignatoryInput input)
{
if (signatory == null) throw new ArgumentNullException(nameof(signatory));
if (input == null) throw new ArgumentNullException(nameof(input));

input.signatoryId = signatory.id;
return await ChangeSignatory(input).ConfigureAwait(false);
}

public async Task<Signatory> ChangeSignatory(string signatoryId, ChangeSignatoryInput input)
{
if (signatoryId == null) throw new ArgumentNullException(nameof(signatoryId));
if (input == null) throw new ArgumentNullException(nameof(input));

input.signatoryId = signatoryId;
return await ChangeSignatory(input).ConfigureAwait(false);
}

public async Task<SignatureOrder> CloseSignatureOrder(CloseSignatureOrderInput input)
{
var data = await SendMutation(
Expand Down
52 changes: 52 additions & 0 deletions Criipto.Signatures/Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,58 @@ fragment BasicSignatory on Signatory {
}


public class ChangeSignatoryMutation {
/// <summary>
/// ChangeSignatoryMutation.Request
/// <para>Required variables:<br/> { input=(ChangeSignatoryInput) }</para>
/// <para>Optional variables:<br/> { }</para>
/// </summary>
public static GraphQLRequest Request(object variables = null) {
return new GraphQLRequest {
Query = ChangeSignatoryDocument,
OperationName = "changeSignatory",
Variables = variables
};
}

/// <remarks>This method is obsolete. Use Request instead.</remarks>
public static GraphQLRequest getChangeSignatoryMutation() {
return Request();
}

public static string ChangeSignatoryDocument = @"
mutation changeSignatory($input: ChangeSignatoryInput!) {
changeSignatory(input: $input) {
signatory {
...BasicSignatory
}
}
}
fragment BasicSignatory on Signatory {
id
status
href
downloadHref
reference
role
evidenceProviders {
__typename
id
}
documents {
edges {
status
node {
__typename
id
}
}
}
}";

}


public class CloseSignatureOrderMutation {
/// <summary>
/// CloseSignatureOrderMutation.Request
Expand Down
8 changes: 8 additions & 0 deletions Criipto.Signatures/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ mutation addSignatory($input: AddSignatoryInput!) {
}
}

mutation changeSignatory($input: ChangeSignatoryInput!) {
changeSignatory(input: $input) {
signatory {
...BasicSignatory
}
}
}

mutation closeSignatureOrder($input: CloseSignatureOrderInput!) {
closeSignatureOrder(input: $input) {
signatureOrder {
Expand Down

0 comments on commit 673fe2c

Please sign in to comment.