Skip to content

Commit

Permalink
Test improvements (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-Roberto-Mancinelli authored Nov 22, 2024
1 parent 774594c commit efbf3aa
Show file tree
Hide file tree
Showing 26 changed files with 371 additions and 364 deletions.
20 changes: 10 additions & 10 deletions test/TrueLayer.AcceptanceTests/AuthTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;
using System.Threading.Tasks;
using Shouldly;
using FluentAssertions;
using TrueLayer.Auth;
using Xunit;

Expand All @@ -21,14 +21,14 @@ public async Task Can_get_auth_token()
ApiResponse<GetAuthTokenResponse> apiResponse
= await _fixture.Client.Auth.GetAuthToken(new GetAuthTokenRequest());

apiResponse.IsSuccessful.ShouldBeTrue();
apiResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
apiResponse.Data.ShouldNotBeNull();
apiResponse.IsSuccessful.Should().BeTrue();
apiResponse.StatusCode.Should().Be(HttpStatusCode.OK);
apiResponse.Data.Should().NotBeNull();

apiResponse.Data.AccessToken.ShouldNotBeNullOrWhiteSpace();
apiResponse.Data.TokenType.ShouldBe("Bearer");
apiResponse.Data.Scope.ShouldNotBeNullOrWhiteSpace();
apiResponse.Data.ExpiresIn.ShouldBeGreaterThan(0);
apiResponse.Data!.AccessToken.Should().NotBeNullOrWhiteSpace();
apiResponse.Data.TokenType.Should().Be("Bearer");
apiResponse.Data.Scope.Should().NotBeNullOrWhiteSpace();
apiResponse.Data.ExpiresIn.Should().BeGreaterThan(0);
}

[Fact]
Expand All @@ -37,8 +37,8 @@ public async Task Can_get_scoped_access_token()
GetAuthTokenResponse? apiResponse
= await _fixture.Client.Auth.GetAuthToken(new GetAuthTokenRequest("payments"));

apiResponse.ShouldNotBeNull();
apiResponse.Scope.ShouldBe("payments");
apiResponse.Should().NotBeNull();
apiResponse!.Scope.Should().Be("payments");
}
}
}
66 changes: 33 additions & 33 deletions test/TrueLayer.AcceptanceTests/MandatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using OneOf;
using Shouldly;
using TrueLayer.Mandates.Model;
using TrueLayer.Payments.Model;
using Xunit;
Expand Down Expand Up @@ -61,8 +61,8 @@ public async Task Can_create_mandate(CreateMandateRequest mandateRequest)
mandateRequest, idempotencyKey: Guid.NewGuid().ToString());

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.Created);
response.Data!.User.Id.ShouldBe(mandateRequest.User!.Id);
response.StatusCode.Should().Be(HttpStatusCode.Created);
response.Data!.User.Id.Should().Be(mandateRequest.User!.Id);
}


Expand All @@ -76,15 +76,15 @@ public async Task Can_get_mandate(CreateMandateRequest mandateRequest)
// Arrange
var createResponse = await _fixture.Client.Mandates.CreateMandate(
mandateRequest, idempotencyKey: Guid.NewGuid().ToString());
createResponse.StatusCode.ShouldBe(HttpStatusCode.Created);
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);
var mandateId = createResponse.Data!.Id;

// Act
var response = await _fixture.Client.Mandates.GetMandate(mandateId, MandateType.Sweeping);

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.Data.AsT0.User!.Id.ShouldBe(createResponse.Data.User!.Id);
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Data.AsT0.User!.Id.Should().Be(createResponse.Data.User!.Id);
}

[Theory]
Expand All @@ -97,14 +97,14 @@ public async Task Can_list_mandate(CreateMandateRequest mandateRequest)
// Arrange
var createResponse = await _fixture.Client.Mandates.CreateMandate(
mandateRequest, idempotencyKey: Guid.NewGuid().ToString());
createResponse.StatusCode.ShouldBe(HttpStatusCode.Created);
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);

// Act
var response = await _fixture.Client.Mandates.ListMandates(new ListMandatesQuery(createResponse.Data!.User.Id, null, 10), MandateType.Sweeping);

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.Data!.Items.Count().ShouldBeLessThanOrEqualTo(10);
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Data!.Items.Count().Should().BeLessThanOrEqualTo(10);
}

[Theory]
Expand All @@ -126,9 +126,9 @@ public async Task Can_start_authorization(CreateMandateRequest mandateRequest)
var mandate = await WaitForMandateToBeAuthorized(mandateId);

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
mandate.AsT2.Status.ShouldBe("authorized");
createResponse.StatusCode.ShouldBe(HttpStatusCode.Created);
response.StatusCode.Should().Be(HttpStatusCode.OK);
mandate.AsT2.Status.Should().Be("authorized");
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);
}

[Theory]
Expand All @@ -151,8 +151,8 @@ await _fixture.Client.Mandates.StartAuthorizationFlow(
mandateId, request, idempotencyKey: Guid.NewGuid().ToString(), MandateType.Sweeping);

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
createResponse.StatusCode.ShouldBe(HttpStatusCode.Created);
response.StatusCode.Should().Be(HttpStatusCode.OK);
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);
}

[Theory]
Expand Down Expand Up @@ -187,7 +187,7 @@ await _fixture.Client.Mandates.SubmitProviderSelection(
mandateId, idempotencyKey: Guid.NewGuid().ToString(), mandateType);

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.StatusCode.Should().Be(HttpStatusCode.OK);
}

[Theory]
Expand All @@ -210,9 +210,9 @@ public async Task Can_Get_Funds(CreateMandateRequest mandateRequest)
var fundsResponse = await _fixture.Client.Mandates.GetConfirmationOfFunds(mandateId, 1, "GBP", MandateType.Sweeping);

// Assert
fundsResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
fundsResponse.Data!.ConfirmedAt.Date.ShouldBe(DateTime.UtcNow.Date);
fundsResponse.Data!.Confirmed.ShouldBeTrue();
fundsResponse.StatusCode.Should().Be(HttpStatusCode.OK);
fundsResponse.Data!.ConfirmedAt.Date.Should().Be(DateTime.UtcNow.Date);
fundsResponse.Data!.Confirmed.Should().BeTrue();
}

[Theory]
Expand All @@ -230,7 +230,7 @@ public async Task Can_get_mandate_constraints(CreateMandateRequest mandateReques
sweepingMandate => MandateType.Sweeping));

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.StatusCode.Should().Be(HttpStatusCode.OK);
}

[Theory]
Expand All @@ -249,7 +249,7 @@ public async Task Can_revoke_mandate(CreateMandateRequest mandateRequest)
sweepingMandate => MandateType.Sweeping));

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
}

[Theory]
Expand All @@ -267,13 +267,13 @@ public async Task Can_create_mandate_payment(CreateMandateRequest mandateRequest
idempotencyKey: Guid.NewGuid().ToString());

// Assert
response.StatusCode.ShouldBe(HttpStatusCode.Created);
response.Data.IsT1.ShouldBeTrue();
response.Data.AsT1.Id.ShouldNotBeNullOrWhiteSpace();
response.Data.AsT1.ResourceToken.ShouldNotBeNullOrWhiteSpace();
response.Data.AsT1.User.ShouldNotBeNull();
response.Data.AsT1.User.Id.ShouldNotBeNullOrWhiteSpace();
response.Data.AsT1.Status.ShouldBe("authorized");
response.StatusCode.Should().Be(HttpStatusCode.Created);
response.Data.IsT1.Should().BeTrue();
response.Data.AsT1.Id.Should().NotBeNullOrWhiteSpace();
response.Data.AsT1.ResourceToken.Should().NotBeNullOrWhiteSpace();
response.Data.AsT1.User.Should().NotBeNull();
response.Data.AsT1.User.Id.Should().NotBeNullOrWhiteSpace();
response.Data.AsT1.Status.Should().Be("authorized");
}

private static CreateMandateRequest CreateTestMandateRequest(
Expand Down Expand Up @@ -331,7 +331,7 @@ await client.PostAsync(
authUri,
new StringContent(jsonPayload, Encoding.UTF8, "application/json"));

submitProviderParamsResponse.IsSuccessStatusCode.ShouldBeTrue();
submitProviderParamsResponse.IsSuccessStatusCode.Should().BeTrue();
}

private async Task<MandateDetailUnion> WaitForMandateToBeAuthorized(string mandateId)
Expand All @@ -354,7 +354,7 @@ private async Task<string> CreateAuthorizedSweepingMandate(CreateMandateRequest
mandateRequest, idempotencyKey: Guid.NewGuid().ToString());
var mandateId = createResponse.Data!.Id;

createResponse.StatusCode.ShouldBe(HttpStatusCode.Created);
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);

StartAuthorizationFlowRequest authorizationRequest = new(
new ProviderSelectionRequest(),
Expand All @@ -367,7 +367,7 @@ private async Task<string> CreateAuthorizedSweepingMandate(CreateMandateRequest
return mandateId;
}

private static IEnumerable<CreateMandateRequest[]> CreateTestSweepingPreselectedMandateRequests()
public static IEnumerable<object[]> CreateTestSweepingPreselectedMandateRequests()
{
yield return new[]
{
Expand All @@ -381,7 +381,7 @@ private static IEnumerable<CreateMandateRequest[]> CreateTestSweepingPreselected
};
}

private static IEnumerable<CreateMandateRequest[]> CreateTestCommercialPreselectedMandateRequests()
public static IEnumerable<object[]> CreateTestCommercialPreselectedMandateRequests()
{
yield return new[]
{
Expand All @@ -395,7 +395,7 @@ private static IEnumerable<CreateMandateRequest[]> CreateTestCommercialPreselect
};
}

private static IEnumerable<CreateMandateRequest[]> CreateTestSweepingUserSelectedMandateRequests()
public static IEnumerable<object[]> CreateTestSweepingUserSelectedMandateRequests()
{
yield return new[]
{
Expand All @@ -412,7 +412,7 @@ private static IEnumerable<CreateMandateRequest[]> CreateTestSweepingUserSelecte
};
}

private static IEnumerable<CreateMandateRequest[]> CreateTestCommercialUserSelectedMandateRequests()
public static IEnumerable<object[]> CreateTestCommercialUserSelectedMandateRequests()
{
yield return new[]
{
Expand Down
Loading

0 comments on commit efbf3aa

Please sign in to comment.