Skip to content

Commit

Permalink
Remove need for AcceptAgreementRequest, use additional params for Acc…
Browse files Browse the repository at this point in the history
…eptAgreement method instead
  • Loading branch information
RobinTTY committed May 13, 2024
1 parent c1eaff6 commit 280b9dd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public async Task CreateAcceptAndDeleteAgreement()
});

// Accept the agreement (should fail)
var acceptMetadata = new AcceptAgreementRequest("example_user_agent", "192.168.178.1");
var acceptResponse = await _apiClient.AgreementsEndpoint.AcceptAgreement(response.Result!.Id, acceptMetadata);
var acceptResponse = await _apiClient.AgreementsEndpoint.AcceptAgreement(response.Result!.Id, "example_user_agent", "192.168.178.1");
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(acceptResponse, HttpStatusCode.Forbidden);
Assert.That(acceptResponse.Error!.Detail,
Is.EqualTo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FakeItEasy;
using RobinTTY.NordigenApiClient.Models.Requests;
using RobinTTY.NordigenApiClient.Models.Responses;
using RobinTTY.NordigenApiClient.Tests.Shared;

Expand Down Expand Up @@ -99,6 +98,28 @@ public async Task CreateAgreement()
});
}

/// <summary>
/// Tests the process of accepting an end user agreement.
/// </summary>
[Test]
public async Task AcceptAgreement()
{
var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.AcceptAgreement,
HttpStatusCode.Forbidden);

var result =
await apiClient.AgreementsEndpoint.AcceptAgreement(A.Dummy<Guid>(), A.Dummy<string>(), A.Dummy<string>());

AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(result, HttpStatusCode.Forbidden);
Assert.Multiple(() =>
{
Assert.That(result.Error?.Summary, Is.EqualTo("Insufficient permissions"));
Assert.That(result.Error?.Detail,
Is.EqualTo(
"Your company doesn't have permission to accept EUA. You'll have to use our default form for this action."));
});
}

/// <summary>
/// Tests the creation of end user agreements.
/// </summary>
Expand All @@ -109,6 +130,7 @@ public async Task DeleteAgreement()
HttpStatusCode.OK);

var result = await apiClient.AgreementsEndpoint.DeleteAgreement(A.Dummy<Guid>());

AssertionHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK);
Assert.Multiple(() =>
{
Expand Down Expand Up @@ -246,4 +268,4 @@ public async Task CreateAgreementWithInvalidParamsAtPolishInstitution()
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ internal class AccountsEndpointMockData(

internal class AgreementsEndpointMockData(
ResponsePage<Agreement> getAgreements,
Agreement createAgreement,
Agreement getAgreement,
Agreement createAgreement,
BasicResponse acceptAgreement,
BasicResponse deleteAgreement,
BasicResponse getAgreementWithInvalidGuid,
CreateAgreementError createAgreementWithInvalidInstitutionId,
Expand All @@ -54,8 +55,9 @@ internal class AgreementsEndpointMockData(
CreateAgreementError createAgreementWithInvalidParamsAtPolishInstitution)
{
public ResponsePage<Agreement> GetAgreements { get; set; } = getAgreements;
public Agreement CreateAgreement { get; set; } = createAgreement;
public Agreement GetAgreement { get; set; } = getAgreement;
public Agreement CreateAgreement { get; set; } = createAgreement;
public BasicResponse AcceptAgreement { get; set; } = acceptAgreement;
public BasicResponse DeleteAgreement { get; set; } = deleteAgreement;

public BasicResponse GetAgreementWithInvalidGuid { get; set; } = getAgreementWithInvalidGuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
"transactions"
]
},
"AcceptAgreement": {
"summary": "Insufficient permissions",
"detail": "Your company doesn't have permission to accept EUA. You'll have to use our default form for this action.",
"status_code": 403
},
"DeleteAgreement": {
"summary": "End User Agreement deleted",
"detail": "End User Agreement bb37bc52-5b1d-44f9-b1cd-ec9594f25387 deleted"
Expand Down
17 changes: 9 additions & 8 deletions src/RobinTTY.NordigenApiClient/Contracts/IAgreementsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RobinTTY.NordigenApiClient.Models.Errors;
using RobinTTY.NordigenApiClient.Models.Requests;
using RobinTTY.NordigenApiClient.Models.Responses;

namespace RobinTTY.NordigenApiClient.Contracts;
Expand Down Expand Up @@ -79,19 +78,21 @@ Task<NordigenApiResponse<BasicResponse, BasicResponse>> DeleteAgreement(string i
/// Accepts an end user agreement. Only available to customers with an enterprise contract at Nordigen.
/// </summary>
/// <param name="id">The id of the end user agreement to accept.</param>
/// <param name="metadata">The metadata required to accept the end user agreement.</param>
/// <param name="userAgent">User agent of the client that accepts the request.</param>
/// <param name="ipAddress">IP address of the client that accepts the request.</param>
/// <param name="cancellationToken">Optional token to signal cancellation of the operation.</param>
/// <returns>A <see cref="NordigenApiResponse{TResponse, TError}" /> which contains the accepted end user agreement.</returns>
Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(Guid id,
AcceptAgreementRequest metadata, CancellationToken cancellationToken = default);
Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(Guid id, string userAgent, string ipAddress,
CancellationToken cancellationToken = default);

/// <summary>
/// Accepts an end user agreement. Only available to customers with an enterprise contract at Nordigen.
/// </summary>
/// <param name="id">The id of the end user agreement to accept.</param>
/// <param name="metadata">The metadata required to accept the end user agreement.</param>
/// <param name="userAgent">User agent of the client that accepts the request.</param>
/// <param name="ipAddress">IP address of the client that accepts the request.</param>
/// <param name="cancellationToken">Optional token to signal cancellation of the operation.</param>
/// <returns>A <see cref="NordigenApiResponse{TResponse, TError}" /> which contains the accepted end user agreement.</returns>
Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(string id,
AcceptAgreementRequest metadata, CancellationToken cancellationToken = default);
}
Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(string id, string userAgent, string ipAddress,
CancellationToken cancellationToken = default);
}
13 changes: 7 additions & 6 deletions src/RobinTTY.NordigenApiClient/Endpoints/AgreementsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public async Task<NordigenApiResponse<BasicResponse, BasicResponse>> DeleteAgree

/// <inheritdoc />
public async Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(Guid id,
AcceptAgreementRequest metadata, CancellationToken cancellationToken = default) =>
await AcceptAgreementInternal(id.ToString(), metadata, cancellationToken);
string userAgent, string ipAddress, CancellationToken cancellationToken = default) =>
await AcceptAgreementInternal(id.ToString(), userAgent, ipAddress, cancellationToken);

/// <inheritdoc />
public async Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreement(string id,
AcceptAgreementRequest metadata, CancellationToken cancellationToken = default) =>
await AcceptAgreementInternal(id, metadata, cancellationToken);
string userAgent, string ipAddress, CancellationToken cancellationToken = default) =>
await AcceptAgreementInternal(id, userAgent, ipAddress, cancellationToken);

private async Task<NordigenApiResponse<Agreement, BasicResponse>> GetAgreementInternal(string id,
CancellationToken cancellationToken) =>
Expand All @@ -84,9 +84,10 @@ await _nordigenClient.MakeRequest<BasicResponse, BasicResponse>(
$"{NordigenEndpointUrls.AgreementsEndpoint}{id}/", HttpMethod.Delete, cancellationToken);

private async Task<NordigenApiResponse<Agreement, BasicResponse>> AcceptAgreementInternal(string id,
AcceptAgreementRequest metadata, CancellationToken cancellationToken)
string userAgent, string ipAddress, CancellationToken cancellationToken)
{
var body = JsonContent.Create(metadata);
var acceptAgreementRequest = new AcceptAgreementRequest(userAgent, ipAddress);
var body = JsonContent.Create(acceptAgreementRequest);
return await _nordigenClient.MakeRequest<Agreement, BasicResponse>(
$"{NordigenEndpointUrls.AgreementsEndpoint}{id}/accept/", HttpMethod.Put, cancellationToken, body: body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace RobinTTY.NordigenApiClient.Models.Requests;
/// <summary>
/// The metadata required to accept an end user agreement via the Nordigen API.
/// </summary>
public class AcceptAgreementRequest
internal class AcceptAgreementRequest
{
/// <summary>
/// User agent of the client that accepts the request.
Expand All @@ -14,7 +14,7 @@ public class AcceptAgreementRequest
public string UserAgent { get; set; }

/// <summary>
/// IP address of the client.
/// IP address of the client that accepts the request.
/// </summary>
[JsonPropertyName("ip_address")]
public string IpAddress { get; set; }
Expand All @@ -23,7 +23,7 @@ public class AcceptAgreementRequest
/// Creates a new instance of <see cref="AcceptAgreementRequest" />.
/// </summary>
/// <param name="userAgent">User agent of the client that accepts the request.</param>
/// <param name="ipAddress">IP address of the client.</param>
/// <param name="ipAddress">IP address of the client that accepts the request.</param>
public AcceptAgreementRequest(string userAgent, string ipAddress)
{
UserAgent = userAgent;
Expand Down

0 comments on commit 280b9dd

Please sign in to comment.