diff --git a/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs b/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs
index ec8f187..3dee5b3 100644
--- a/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs
+++ b/src/RobinTTY.NordigenApiClient.Tests/LiveApi/Endpoints/AgreementsEndpointTests.cs
@@ -101,19 +101,6 @@ public async Task GetAgreement()
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(deleteResponse, HttpStatusCode.OK);
}
- ///
- /// Tests the retrieval of an agreement with an invalid guid.
- ///
- [Test]
- public async Task GetAgreementWithInvalidGuid()
- {
- const string guid = "f84d7b8-dee4-4cd9-bc6d-842ef78f6028";
- var response = await _apiClient.AgreementsEndpoint.GetAgreement(guid);
- AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
- AssertionHelpers.AssertBasicResponseMatchesExpectations(response.Error, "Invalid EndUserAgreement ID",
- $"{guid} is not a valid EndUserAgreement UUID. ");
- }
-
///
/// Tests the creation and deletion of an end user agreement.
///
@@ -156,24 +143,20 @@ public async Task CreateAcceptAndDeleteAgreement()
#region RequestsWithErrors
///
- /// Tests the retrieving of an end user agreement with an invalid institution id.
+ /// Tests the retrieval of an agreement with an invalid guid.
///
[Test]
- public async Task GetAgreementWithInvalidInstitutionId()
+ public async Task GetAgreementWithInvalidGuid()
{
- var agreement = new CreateAgreementRequest(90, 90,
- ["balances", "details", "transactions"], "invalid_institution");
+ const string guid = "f84d7b8-dee4-4cd9-bc6d-842ef78f6028";
- var response = await _apiClient.AgreementsEndpoint.CreateAgreement(agreement);
+ var response = await _apiClient.AgreementsEndpoint.GetAgreement(guid);
- AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
Assert.Multiple(() =>
{
- Assert.That(response.Error!.InstitutionIdError, Is.Not.Null);
- Assert.That(response.Error!.InstitutionIdError!.Summary,
- Is.EqualTo("Unknown Institution ID invalid_institution"));
- Assert.That(response.Error!.InstitutionIdError!.Detail,
- Is.EqualTo("Get Institution IDs from /institutions/?country={$COUNTRY_CODE}"));
+ AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
+ AssertionHelpers.AssertBasicResponseMatchesExpectations(response.Error, "Invalid EndUserAgreement ID",
+ $"{guid} is not a valid EndUserAgreement UUID. ");
});
}
@@ -232,15 +215,14 @@ public async Task CreateAgreementWithInvalidParamsAtPolishInstitution()
["balances", "transactions"], "PKO_BPKOPLPW");
var response = await _apiClient.AgreementsEndpoint.CreateAgreement(agreement);
- var result = response.Error!;
Assert.Multiple(() =>
{
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
- Assert.That(new[] {result.InstitutionIdError, result.AgreementError}, Has.All.Null);
- Assert.That(result.Detail,
+ Assert.That(new[] {response.Error!.InstitutionIdError, response.Error!.AgreementError}, Has.All.Null);
+ Assert.That(response.Error!.Detail,
Is.EqualTo("For this institution the following scopes are required together: ['details', 'balances']"));
- Assert.That(result.Summary, Is.EqualTo("Institution access scope dependencies error"));
+ Assert.That(response.Error!.Summary, Is.EqualTo("Institution access scope dependencies error"));
});
}
diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs
index f58a0e6..84b562b 100644
--- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs
+++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Endpoints/AgreementsEndpointTests.cs
@@ -6,13 +6,16 @@ namespace RobinTTY.NordigenApiClient.Tests.Mocks.Endpoints;
public class AgreementsEndpointTests
{
+ #region RequestsWithSuccessfulResponse
+
///
/// Tests the retrieval of end user agreements.
///
[Test]
public async Task GetAgreements()
{
- var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.GetAgreements, HttpStatusCode.OK);
+ var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.GetAgreements,
+ HttpStatusCode.OK);
var agreements = await apiClient.AgreementsEndpoint.GetAgreements(100, 0);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(agreements, HttpStatusCode.OK);
@@ -50,7 +53,8 @@ public async Task GetAgreements()
[Test]
public async Task GetAgreement()
{
- var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.GetAgreement, HttpStatusCode.OK);
+ var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.GetAgreement,
+ HttpStatusCode.OK);
var agreement = await apiClient.AgreementsEndpoint.GetAgreement(A.Dummy());
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(agreement, HttpStatusCode.OK);
@@ -76,7 +80,8 @@ public async Task GetAgreement()
[Test]
public async Task CreateAgreement()
{
- var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.CreateAgreement, HttpStatusCode.Created);
+ var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.CreateAgreement,
+ HttpStatusCode.Created);
var agreementRequest = new CreateAgreementRequest(145, 145,
["balances", "details", "transactions"], "SANDBOXFINANCE_SFIN0000");
@@ -101,14 +106,118 @@ public async Task CreateAgreement()
[Test]
public async Task DeleteAgreement()
{
- var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.DeleteAgreement, HttpStatusCode.OK);
+ var apiClient = TestHelpers.GetMockClient(TestHelpers.MockData.AgreementsEndpointMockData.DeleteAgreement,
+ HttpStatusCode.OK);
var result = await apiClient.AgreementsEndpoint.DeleteAgreement(A.Dummy());
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK);
Assert.Multiple(() =>
{
Assert.That(result.Result?.Summary, Is.EqualTo("End User Agreement deleted"));
- Assert.That(result.Result?.Detail, Is.EqualTo("End User Agreement bb37bc52-5b1d-44f9-b1cd-ec9594f25387 deleted"));
+ Assert.That(result.Result?.Detail,
+ Is.EqualTo("End User Agreement bb37bc52-5b1d-44f9-b1cd-ec9594f25387 deleted"));
+ });
+ }
+
+ #endregion
+
+ #region RequestsWithErrors
+
+ ///
+ /// Tests the retrieval of an agreement with an invalid guid.
+ ///
+ [Test]
+ public async Task GetAgreementWithInvalidGuid()
+ {
+ const string guid = "f84d7b8-dee4-4cd9-bc6d-842ef78f6028";
+ var apiClient = TestHelpers.GetMockClient(
+ TestHelpers.MockData.AgreementsEndpointMockData.GetAgreementWithInvalidGuid,
+ HttpStatusCode.BadRequest);
+
+ var response = await apiClient.AgreementsEndpoint.GetAgreement(guid);
+
+ Assert.Multiple(() =>
+ {
+ AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
+ AssertionHelpers.AssertBasicResponseMatchesExpectations(response.Error, "Invalid EndUserAgreement ID",
+ $"{guid} is not a valid EndUserAgreement UUID. ");
+ });
+ }
+
+ ///
+ /// Tests the creation of an end user agreement with an invalid institution id.
+ ///
+ [Test]
+ public async Task CreateAgreementWithInvalidInstitutionId()
+ {
+ var apiClient = TestHelpers.GetMockClient(
+ TestHelpers.MockData.AgreementsEndpointMockData.CreateAgreementWithInvalidInstitutionId,
+ HttpStatusCode.BadRequest);
+ var agreement = new CreateAgreementRequest(90, 90,
+ ["balances", "details", "transactions"], "invalid_institution");
+
+ var response = await apiClient.AgreementsEndpoint.CreateAgreement(agreement);
+
+ AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
+ Assert.Multiple(() =>
+ {
+ Assert.That(response.Error!.InstitutionIdError, Is.Not.Null);
+ Assert.That(response.Error!.InstitutionIdError!.Summary,
+ Is.EqualTo("Unknown Institution ID invalid_institution"));
+ Assert.That(response.Error!.InstitutionIdError!.Detail,
+ Is.EqualTo("Get Institution IDs from /institutions/?country={$COUNTRY_CODE}"));
});
}
+
+ ///
+ /// Tests the creation of an end user agreement with invalid parameters.
+ ///
+ [Test]
+ public async Task CreateAgreementWithInvalidParams()
+ {
+ var apiClient = TestHelpers.GetMockClient(
+ TestHelpers.MockData.AgreementsEndpointMockData.CreateAgreementWithInvalidParams,
+ HttpStatusCode.BadRequest);
+ var agreement = new CreateAgreementRequest(200, 200,
+ ["balances", "details", "transactions", "invalid", "invalid2"], "SANDBOXFINANCE_SFIN0000");
+
+ var response = await apiClient.AgreementsEndpoint.CreateAgreement(agreement);
+ var result = response.Error!;
+
+ Assert.Multiple(() =>
+ {
+ AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
+ Assert.That(new[] {result.InstitutionIdError, result.AgreementError}, Has.All.Null);
+ Assert.That(result.AccessScopeError!.Detail,
+ Is.EqualTo("Choose one or several from ['balances', 'details', 'transactions']"));
+ Assert.That(result.AccessValidForDaysError!.Detail,
+ Is.EqualTo("access_valid_for_days must be > 0 and <= 180"));
+ Assert.That(result.MaxHistoricalDaysError!.Detail,
+ Is.EqualTo(
+ "max_historical_days must be > 0 and <= SANDBOXFINANCE_SFIN0000 transaction_total_days (90)"));
+ });
+ }
+
+ [Test]
+ public async Task CreateAgreementWithInvalidParamsAtPolishInstitution()
+ {
+ var apiClient = TestHelpers.GetMockClient(
+ TestHelpers.MockData.AgreementsEndpointMockData.CreateAgreementWithInvalidParamsAtPolishInstitution,
+ HttpStatusCode.BadRequest);
+ var agreement = new CreateAgreementRequest(90, 90,
+ ["balances", "transactions"], "PKO_BPKOPLPW");
+
+ var response = await apiClient.AgreementsEndpoint.CreateAgreement(agreement);
+
+ Assert.Multiple(() =>
+ {
+ AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
+ Assert.That(new[] {response.Error!.InstitutionIdError, response.Error!.AgreementError}, Has.All.Null);
+ Assert.That(response.Error!.Detail,
+ Is.EqualTo("For this institution the following scopes are required together: ['details', 'balances']"));
+ Assert.That(response.Error!.Summary, Is.EqualTo("Institution access scope dependencies error"));
+ });
+ }
+
+ #endregion
}
diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs
index f1f5384..8675aa6 100644
--- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs
+++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/MockResponsesModel.cs
@@ -46,12 +46,26 @@ internal class AgreementsEndpointMockData(
ResponsePage getAgreements,
Agreement createAgreement,
Agreement getAgreement,
- BasicResponse deleteAgreement)
+ BasicResponse deleteAgreement,
+ BasicResponse getAgreementWithInvalidGuid,
+ CreateAgreementError createAgreementWithInvalidInstitutionId,
+ CreateAgreementError createAgreementWithInvalidParams,
+ CreateAgreementError createAgreementWithInvalidParamsAtPolishInstitution)
{
public ResponsePage GetAgreements { get; set; } = getAgreements;
public Agreement CreateAgreement { get; set; } = createAgreement;
public Agreement GetAgreement { get; set; } = getAgreement;
public BasicResponse DeleteAgreement { get; set; } = deleteAgreement;
+
+ public BasicResponse GetAgreementWithInvalidGuid { get; set; } = getAgreementWithInvalidGuid;
+
+ public CreateAgreementError CreateAgreementWithInvalidInstitutionId { get; set; } =
+ createAgreementWithInvalidInstitutionId;
+
+ public CreateAgreementError CreateAgreementWithInvalidParams { get; set; } = createAgreementWithInvalidParams;
+
+ public CreateAgreementError CreateAgreementWithInvalidParamsAtPolishInstitution { get; set; } =
+ createAgreementWithInvalidParamsAtPolishInstitution;
}
internal class InstitutionsEndpointMockData(List getInstitutions, Institution getInstitution)
diff --git a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json
index 1a00ef2..7dd302e 100644
--- a/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json
+++ b/src/RobinTTY.NordigenApiClient.Tests/Mocks/Responses/responses.json
@@ -199,6 +199,42 @@
"DeleteAgreement": {
"summary": "End User Agreement deleted",
"detail": "End User Agreement bb37bc52-5b1d-44f9-b1cd-ec9594f25387 deleted"
+ },
+ "GetAgreementWithInvalidGuid": {
+ "summary": "Invalid EndUserAgreement ID",
+ "detail": "f84d7b8-dee4-4cd9-bc6d-842ef78f6028 is not a valid EndUserAgreement UUID. ",
+ "status_code": 400
+ },
+ "CreateAgreementWithInvalidInstitutionId": {
+ "institution_id": {
+ "summary": "Unknown Institution ID invalid_institution",
+ "detail": "Get Institution IDs from /institutions/?country\u003d{$COUNTRY_CODE}"
+ },
+ "status_code": 400
+ },
+ "CreateAgreementWithInvalidParams": {
+ "max_historical_days": {
+ "summary": "Incorrect max_historical_days",
+ "detail": "max_historical_days must be \u003e 0 and \u003c\u003d SANDBOXFINANCE_SFIN0000 transaction_total_days (90)"
+ },
+ "access_valid_for_days": {
+ "summary": "Incorrect access_valid_for_days",
+ "detail": "access_valid_for_days must be \u003e 0 and \u003c\u003d 180"
+ },
+ "access_scope": {
+ "summary": "Unknown value \u0027[\u0027invalid2\u0027, \u0027invalid\u0027]\u0027 in access_scope",
+ "detail": "Choose one or several from [\u0027balances\u0027, \u0027details\u0027, \u0027transactions\u0027]"
+ },
+ "status_code": 400
+ },
+ "CreateAgreementWithInvalidParamsAtPolishInstitution": {
+ "summary": [
+ "Institution access scope dependencies error"
+ ],
+ "detail": [
+ "For this institution the following scopes are required together: [\u0027details\u0027, \u0027balances\u0027]"
+ ],
+ "status_code": 400
}
},
"InstitutionsEndpointMockData": {