Skip to content

Commit

Permalink
Simplify TestHelpers, add test for unsuccessful token retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Apr 18, 2024
1 parent 8050001 commit a3c59b3
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Setup()
public async Task GetAccount()
{
var accountResponse = await _apiClient.AccountsEndpoint.GetAccount(_accountId);
TestHelpers.AssertNordigenApiResponseIsSuccessful(accountResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(accountResponse, HttpStatusCode.OK);
var account = accountResponse.Result!;
Assert.Multiple(() =>
{
Expand All @@ -41,7 +41,7 @@ public async Task GetAccount()
public async Task GetBalances()
{
var balancesResponse = await _apiClient.AccountsEndpoint.GetBalances(_accountId);
TestHelpers.AssertNordigenApiResponseIsSuccessful(balancesResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(balancesResponse, HttpStatusCode.OK);
var balances = balancesResponse.Result!;
Assert.Multiple(() =>
{
Expand All @@ -59,7 +59,7 @@ public async Task GetBalances()
public async Task GetAccountDetails()
{
var detailsResponse = await _apiClient.AccountsEndpoint.GetAccountDetails(_accountId);
TestHelpers.AssertNordigenApiResponseIsSuccessful(detailsResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(detailsResponse, HttpStatusCode.OK);
var details = detailsResponse.Result!;
Assert.Multiple(() =>
{
Expand All @@ -77,7 +77,7 @@ public async Task GetAccountDetails()
public async Task GetTransactions()
{
var transactionsResponse = await _apiClient.AccountsEndpoint.GetTransactions(_accountId);
TestHelpers.AssertNordigenApiResponseIsSuccessful(transactionsResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(transactionsResponse, HttpStatusCode.OK);
var transactions = transactionsResponse.Result!;
Assert.Multiple(() =>
{
Expand Down Expand Up @@ -114,7 +114,7 @@ await _apiClient.AccountsEndpoint.GetTransactions(_accountId, startDate,
DateTime.Now.Subtract(TimeSpan.FromDays(1)));
#endif

TestHelpers.AssertNordigenApiResponseIsSuccessful(balancesResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(balancesResponse, HttpStatusCode.OK);
Assert.That(balancesResponse.Result!.BookedTransactions, Has.Count.AtLeast(6));
}

Expand All @@ -133,7 +133,7 @@ await _apiClient.AccountsEndpoint.GetTransactions(_accountId, DateOnly.FromDateT
var balancesResponse =
await _apiClient.AccountsEndpoint.GetTransactions(_accountId, dateInFuture, dateInFuture.AddDays(1));
#endif
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(balancesResponse, HttpStatusCode.BadRequest);
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(balancesResponse, HttpStatusCode.BadRequest);
Assert.Multiple(() =>
{
Assert.That(balancesResponse.Error!.StartDateError, Is.Not.Null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task GetAgreementsPaged()
{
// Get existing agreements
var existingAgreements = await _apiClient.AgreementsEndpoint.GetAgreements(100, 0);
TestHelpers.AssertNordigenApiResponseIsSuccessful(existingAgreements, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(existingAgreements, HttpStatusCode.OK);

// Create 3 example agreements
var agreementRequest = new CreateAgreementRequest(90, 90,
Expand All @@ -37,21 +37,21 @@ public async Task GetAgreementsPaged()
for (var i = 0; i < 3; i++)
{
var createResponse = await _apiClient.AgreementsEndpoint.CreateAgreement(agreementRequest);
TestHelpers.AssertNordigenApiResponseIsSuccessful(createResponse, HttpStatusCode.Created);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(createResponse, HttpStatusCode.Created);
ids.Add(createResponse.Result!.Id.ToString());
}

// Get a response page for each agreement
var page1Response = await _apiClient.AgreementsEndpoint.GetAgreements(1, 0);
AssertionHelper.AssertThatAgreementPageContainsAgreement(page1Response, ids);
AssertionHelpers.AssertThatAgreementPageContainsAgreement(page1Response, ids);

var page2Response = await page1Response.Result!.GetNextPage(_apiClient);
Assert.That(page2Response, Is.Not.Null);
AssertionHelper.AssertThatAgreementPageContainsAgreement(page2Response!, ids);
AssertionHelpers.AssertThatAgreementPageContainsAgreement(page2Response!, ids);

var page3Response = await page2Response!.Result!.GetNextPage(_apiClient);
Assert.That(page3Response, Is.Not.Null);
AssertionHelper.AssertThatAgreementPageContainsAgreement(page3Response!, ids);
AssertionHelpers.AssertThatAgreementPageContainsAgreement(page3Response!, ids);

// On the last page there should be a Url to the previous one
Assert.That(page3Response!.Result!.Previous, Is.Not.Null);
Expand All @@ -60,7 +60,7 @@ public async Task GetAgreementsPaged()
var previousPageResponse = await page3Response.Result!.GetPreviousPage(_apiClient);
Assert.That(previousPageResponse, Is.Not.Null);

AssertionHelper.AssertThatAgreementPageContainsAgreement(previousPageResponse!, ids);
AssertionHelpers.AssertThatAgreementPageContainsAgreement(previousPageResponse!, ids);

// The previous page agreement id should equal page 2 agreement id
var prevAgreementId = previousPageResponse!.Result!.Results.First().Id;
Expand All @@ -72,7 +72,7 @@ public async Task GetAgreementsPaged()
foreach (var id in ids)
{
var result = await _apiClient.AgreementsEndpoint.DeleteAgreement(id);
TestHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK);
}
}

Expand All @@ -87,19 +87,19 @@ public async Task GetAgreement()
var agreementRequest = new CreateAgreementRequest(90, 90,
["balances", "details", "transactions"], "SANDBOXFINANCE_SFIN0000");
var createResponse = await _apiClient.AgreementsEndpoint.CreateAgreement(agreementRequest);
TestHelpers.AssertNordigenApiResponseIsSuccessful(createResponse, HttpStatusCode.Created);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(createResponse, HttpStatusCode.Created);
var id = createResponse.Result!.Id;

// Get agreement via guid and string id, should retrieve the same agreement
var agreementResponseGuid = await _apiClient.AgreementsEndpoint.GetAgreement(id);
var agreementResponseString = await _apiClient.AgreementsEndpoint.GetAgreement(id.ToString());
TestHelpers.AssertNordigenApiResponseIsSuccessful(agreementResponseGuid, HttpStatusCode.OK);
TestHelpers.AssertNordigenApiResponseIsSuccessful(agreementResponseString, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(agreementResponseGuid, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(agreementResponseString, HttpStatusCode.OK);
Assert.That(agreementResponseGuid.Result!.Id, Is.EqualTo(agreementResponseString.Result!.Id));

// Delete agreement
var deleteResponse = await _apiClient.AgreementsEndpoint.DeleteAgreement(id);
TestHelpers.AssertNordigenApiResponseIsSuccessful(deleteResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(deleteResponse, HttpStatusCode.OK);
}

/// <summary>
Expand All @@ -111,10 +111,9 @@ public async Task GetAgreementWithInvalidGuid()
{
const string guid = "f84d7b8-dee4-4cd9-bc6d-842ef78f6028";
var response = await _apiClient.AgreementsEndpoint.GetAgreement(guid);
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
// TODO: Use TestHelpers
Assert.That(response.Error!.Summary, Is.EqualTo("Invalid EndUserAgreement ID"));
Assert.That(response.Error!.Detail, Is.EqualTo($"{guid} is not a valid EndUserAgreement UUID. "));
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
AssertionHelpers.AssertBasicResponseMatchesExpectations(response.Error, "Invalid EndUserAgreement ID",
$"{guid} is not a valid EndUserAgreement UUID. ");
}

/// <summary>
Expand All @@ -128,7 +127,7 @@ public async Task CreateAcceptAndDeleteAgreement()
var agreement = new CreateAgreementRequest(90, 90, ["balances", "details", "transactions"],
"SANDBOXFINANCE_SFIN0000");
var response = await _apiClient.AgreementsEndpoint.CreateAgreement(agreement);
TestHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.Created);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.Created);

var result = response.Result!;
Assert.Multiple(() =>
Expand All @@ -144,14 +143,14 @@ 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);
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(acceptResponse, HttpStatusCode.Forbidden);
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(acceptResponse, HttpStatusCode.Forbidden);
Assert.That(acceptResponse.Error!.Detail,
Is.EqualTo(
"Your company doesn't have permission to accept EUA. You'll have to use our default form for this action."));

// Delete the agreement
var deletionResponse = await _apiClient.AgreementsEndpoint.DeleteAgreement(result.Id);
TestHelpers.AssertNordigenApiResponseIsSuccessful(deletionResponse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(deletionResponse, HttpStatusCode.OK);
Assert.That(deletionResponse.Result!.Summary, Is.EqualTo("End User Agreement deleted"));
}

Expand All @@ -165,7 +164,7 @@ public async Task CreateAgreementWithInvalidInstitutionId()
var agreement = new CreateAgreementRequest(90, 90, ["balances", "details", "transactions"],
"SANDBOXFINANCE_SFIN000");
var response = await _apiClient.AgreementsEndpoint.CreateAgreement(agreement);
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);

var result = response.Error!;
Assert.That(result.InstitutionIdError, Is.Not.Null);
Expand All @@ -183,7 +182,7 @@ public async Task CreateAgreementWithInvalidParams()
var agreement = new CreateAgreementRequest(200, 200,
["balances", "details", "transactions", "invalid", "invalid2"], "SANDBOXFINANCE_SFIN0000");
var response = await _apiClient.AgreementsEndpoint.CreateAgreement(agreement);
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);

var result = response.Error!;
Assert.Multiple(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void Setup()
public async Task GetInstitutions()
{
var response = await _apiClient.InstitutionsEndpoint.GetInstitutions();
TestHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.OK);
var response2 = await _apiClient.InstitutionsEndpoint.GetInstitutions("GB");
TestHelpers.AssertNordigenApiResponseIsSuccessful(response2, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(response2, HttpStatusCode.OK);

var result = response.Result!.ToList();
var result2 = response2.Result!.ToList();
Expand All @@ -45,18 +45,18 @@ public async Task GetInstitutionsWithFlags()
{
var allFlagsSetTrue = await _apiClient.InstitutionsEndpoint.GetInstitutions("GB", true, true, true, true, true,
true, true, true, true, true, true);
TestHelpers.AssertNordigenApiResponseIsSuccessful(allFlagsSetTrue, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(allFlagsSetTrue, HttpStatusCode.OK);
var allFlagsSetFalse = await _apiClient.InstitutionsEndpoint.GetInstitutions("GB", false, false, false, false,
false, false, false, false, false, false, false);
TestHelpers.AssertNordigenApiResponseIsSuccessful(allFlagsSetFalse, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(allFlagsSetFalse, HttpStatusCode.OK);
var institutionsWithAccountSelection =
await _apiClient.InstitutionsEndpoint.GetInstitutions(accountSelectionSupported: true);
TestHelpers.AssertNordigenApiResponseIsSuccessful(institutionsWithAccountSelection, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(institutionsWithAccountSelection, HttpStatusCode.OK);
var institutionsWithoutAccountSelection =
await _apiClient.InstitutionsEndpoint.GetInstitutions(accountSelectionSupported: false);
TestHelpers.AssertNordigenApiResponseIsSuccessful(institutionsWithoutAccountSelection, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(institutionsWithoutAccountSelection, HttpStatusCode.OK);
var allInstitutions = await _apiClient.InstitutionsEndpoint.GetInstitutions();
TestHelpers.AssertNordigenApiResponseIsSuccessful(allInstitutions, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(allInstitutions, HttpStatusCode.OK);

var allFlagsTrueResult = allFlagsSetTrue.Result!.ToList();
var withAccountSelectionResult = institutionsWithAccountSelection.Result!.ToList();
Expand All @@ -82,7 +82,7 @@ public async Task GetInstitutionsWithFlags()
public async Task GetInstitutionsForNotCoveredCountry()
{
var response = await _apiClient.InstitutionsEndpoint.GetInstitutions("US");
TestHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(response, HttpStatusCode.BadRequest);

Assert.Multiple(() =>
{
Expand All @@ -99,7 +99,7 @@ public async Task GetInstitutionsForNotCoveredCountry()
public async Task GetInstitution()
{
var response = await _apiClient.InstitutionsEndpoint.GetInstitution("SANDBOXFINANCE_SFIN0000");
TestHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.OK);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(response, HttpStatusCode.OK);

var result = response.Result!;
Assert.Multiple(() =>
Expand Down
Loading

0 comments on commit a3c59b3

Please sign in to comment.