From 280b9dd00b06a94dfd41ab43890504cb245b0705 Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Tue, 14 May 2024 00:48:12 +0200 Subject: [PATCH] Remove need for AcceptAgreementRequest, use additional params for AcceptAgreement method instead --- .../Endpoints/AgreementsEndpointTests.cs | 3 +-- .../Endpoints/AgreementsEndpointTests.cs | 26 +++++++++++++++++-- .../Mocks/Responses/MockResponsesModel.cs | 6 +++-- .../Mocks/Responses/responses.json | 5 ++++ .../Contracts/IAgreementsEndpoint.cs | 17 ++++++------ .../Endpoints/AgreementsEndpoint.cs | 13 +++++----- .../Models/Requests/AcceptAgreementRequest.cs | 6 ++--- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs b/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs index 4c8806e..c2fe3be 100644 --- a/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs +++ b/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs @@ -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( diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs index b74e15f..38bdad7 100644 --- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs +++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs @@ -1,5 +1,4 @@ using FakeItEasy; -using RobinTTY.NordigenApiClient.Models.Requests; using RobinTTY.NordigenApiClient.Models.Responses; using RobinTTY.NordigenApiClient.Tests.Shared; @@ -99,6 +98,28 @@ public async Task CreateAgreement() }); } + /// + /// Tests the process of accepting an end user agreement. + /// + [Test] + public async Task AcceptAgreement() + { + var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.AcceptAgreement, + HttpStatusCode.Forbidden); + + var result = + await apiClient.AgreementsEndpoint.AcceptAgreement(A.Dummy(), A.Dummy(), A.Dummy()); + + 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.")); + }); + } + /// /// Tests the creation of end user agreements. /// @@ -109,6 +130,7 @@ public async Task DeleteAgreement() HttpStatusCode.OK); var result = await apiClient.AgreementsEndpoint.DeleteAgreement(A.Dummy()); + AssertionHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK); Assert.Multiple(() => { @@ -246,4 +268,4 @@ public async Task CreateAgreementWithInvalidParamsAtPolishInstitution() } #endregion -} \ No newline at end of file +} diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs index 1f9b3ee..a5881b7 100644 --- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs +++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs @@ -44,8 +44,9 @@ internal class AccountsEndpointMockData( internal class AgreementsEndpointMockData( ResponsePage getAgreements, - Agreement createAgreement, Agreement getAgreement, + Agreement createAgreement, + BasicResponse acceptAgreement, BasicResponse deleteAgreement, BasicResponse getAgreementWithInvalidGuid, CreateAgreementError createAgreementWithInvalidInstitutionId, @@ -54,8 +55,9 @@ internal class AgreementsEndpointMockData( CreateAgreementError createAgreementWithInvalidParamsAtPolishInstitution) { public ResponsePage 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; diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json index 418d2ee..8131767 100644 --- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json +++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json @@ -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" diff --git a/src/RobinTTY.NordigenApiClient/Contracts/IAgreementsEndpoint.cs b/src/RobinTTY.NordigenApiClient/Contracts/IAgreementsEndpoint.cs index 85a976a..28b3bda 100644 --- a/src/RobinTTY.NordigenApiClient/Contracts/IAgreementsEndpoint.cs +++ b/src/RobinTTY.NordigenApiClient/Contracts/IAgreementsEndpoint.cs @@ -1,5 +1,4 @@ using RobinTTY.NordigenApiClient.Models.Errors; -using RobinTTY.NordigenApiClient.Models.Requests; using RobinTTY.NordigenApiClient.Models.Responses; namespace RobinTTY.NordigenApiClient.Contracts; @@ -79,19 +78,21 @@ Task> DeleteAgreement(string i /// Accepts an end user agreement. Only available to customers with an enterprise contract at Nordigen. /// /// The id of the end user agreement to accept. - /// The metadata required to accept the end user agreement. + /// User agent of the client that accepts the request. + /// IP address of the client that accepts the request. /// Optional token to signal cancellation of the operation. /// A which contains the accepted end user agreement. - Task> AcceptAgreement(Guid id, - AcceptAgreementRequest metadata, CancellationToken cancellationToken = default); + Task> AcceptAgreement(Guid id, string userAgent, string ipAddress, + CancellationToken cancellationToken = default); /// /// Accepts an end user agreement. Only available to customers with an enterprise contract at Nordigen. /// /// The id of the end user agreement to accept. - /// The metadata required to accept the end user agreement. + /// User agent of the client that accepts the request. + /// IP address of the client that accepts the request. /// Optional token to signal cancellation of the operation. /// A which contains the accepted end user agreement. - Task> AcceptAgreement(string id, - AcceptAgreementRequest metadata, CancellationToken cancellationToken = default); -} \ No newline at end of file + Task> AcceptAgreement(string id, string userAgent, string ipAddress, + CancellationToken cancellationToken = default); +} diff --git a/src/RobinTTY.NordigenApiClient/Endpoints/AgreementsEndpoint.cs b/src/RobinTTY.NordigenApiClient/Endpoints/AgreementsEndpoint.cs index 08dc429..52281a1 100644 --- a/src/RobinTTY.NordigenApiClient/Endpoints/AgreementsEndpoint.cs +++ b/src/RobinTTY.NordigenApiClient/Endpoints/AgreementsEndpoint.cs @@ -65,13 +65,13 @@ public async Task> DeleteAgree /// public async Task> 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); /// public async Task> 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> GetAgreementInternal(string id, CancellationToken cancellationToken) => @@ -84,9 +84,10 @@ await _nordigenClient.MakeRequest( $"{NordigenEndpointUrls.AgreementsEndpoint}{id}/", HttpMethod.Delete, cancellationToken); private async Task> 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( $"{NordigenEndpointUrls.AgreementsEndpoint}{id}/accept/", HttpMethod.Put, cancellationToken, body: body); } diff --git a/src/RobinTTY.NordigenApiClient/Models/Requests/AcceptAgreementRequest.cs b/src/RobinTTY.NordigenApiClient/Models/Requests/AcceptAgreementRequest.cs index e61acad..9d62c2f 100644 --- a/src/RobinTTY.NordigenApiClient/Models/Requests/AcceptAgreementRequest.cs +++ b/src/RobinTTY.NordigenApiClient/Models/Requests/AcceptAgreementRequest.cs @@ -5,7 +5,7 @@ namespace RobinTTY.NordigenApiClient.Models.Requests; /// /// The metadata required to accept an end user agreement via the Nordigen API. /// -public class AcceptAgreementRequest +internal class AcceptAgreementRequest { /// /// User agent of the client that accepts the request. @@ -14,7 +14,7 @@ public class AcceptAgreementRequest public string UserAgent { get; set; } /// - /// IP address of the client. + /// IP address of the client that accepts the request. /// [JsonPropertyName("ip_address")] public string IpAddress { get; set; } @@ -23,7 +23,7 @@ public class AcceptAgreementRequest /// Creates a new instance of . /// /// User agent of the client that accepts the request. - /// IP address of the client. + /// IP address of the client that accepts the request. public AcceptAgreementRequest(string userAgent, string ipAddress) { UserAgent = userAgent;