Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Handle AggregatedMeasuredData only in EDI #1311

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/B2BApi.AppTests/Fixtures/B2BApiAppFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private FunctionAppHostSettings CreateAppHostSettings(string csprojName, ref int

appHostSettings.ProcessEnvironmentVariables.Add(
"FeatureManagement__RequestStaysInEdi",
false.ToString().ToLower());
true.ToString().ToLower());

appHostSettings.ProcessEnvironmentVariables.Add(
"FeatureManagement__ReceiveMeteredDataForMeasurementPoints",
Expand All @@ -429,7 +429,7 @@ private FunctionAppHostSettings CreateAppHostSettings(string csprojName, ref int

appHostSettings.ProcessEnvironmentVariables.Add(
$"AzureWebJobs.TenSecondsHasPassed.Disabled",
"true");
"false");
lasrinnil marked this conversation as resolved.
Show resolved Hide resolved
appHostSettings.ProcessEnvironmentVariables.Add(
$"AzureWebJobs.ADayHasPassed.Disabled",
"true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics;
using System.Dynamic;
using System.Net;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -83,6 +84,54 @@ public async Task Given_PersistedActor_When_CallingIncomingMessagesWithValidDocu
actualResponse.StatusCode.Should().Be(HttpStatusCode.Accepted);
}

[Fact]
public async Task Given_PersistedActor_When_CallingIncomingMessagesWithValidDocumentAndBearerToken_Then_ResponseShouldBeAccepted_AndRequestCanBePeeked()
{
// Arrange
var actorNumber = ActorNumber.Create("5790000392551");
var externalId = Guid.NewGuid().ToString();
await Fixture.DatabaseManager.AddActorAsync(actorNumber, externalId);

var actorRole = ActorRole.EnergySupplier;
var b2bToken = new JwtBuilder()
.WithRole(ClaimsMap.RoleFrom(actorRole).Value)
.WithClaim(ClaimsMap.ActorId, externalId)
.CreateToken();

using var request = await CreateHttpRequest(
"TestData/Messages/json/RequestAggregatedMeasureData.json",
IncomingDocumentType.RequestAggregatedMeasureData.Name,
"application/json");
lasrinnil marked this conversation as resolved.
Show resolved Hide resolved

// Act
await Fixture.AppHostManager.HttpClient.SendAsync(request);

// Assert
var stopWatch = Stopwatch.StartNew();
var timeoutAfter = TimeSpan.FromMinutes(1);

while (stopWatch.ElapsedMilliseconds < timeoutAfter.TotalMilliseconds)
{
using var peekRequest = new HttpRequestMessage(HttpMethod.Get, $"api/peek/aggregations");
peekRequest.Content = new StringContent(
string.Empty,
Encoding.UTF8,
"application/json");
peekRequest.Headers.Authorization = new AuthenticationHeaderValue("bearer", b2bToken);
using var response = await Fixture.AppHostManager.HttpClient.SendAsync(peekRequest);

if (response.StatusCode == HttpStatusCode.OK)
{
// Assert
response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync()).Should().Contain("RejectRequestAggregatedMeasureData_MarketDocument");
lasrinnil marked this conversation as resolved.
Show resolved Hide resolved
}

await Task.Delay(500);
}
Copy link
Contributor

@ebbeknudsen ebbeknudsen Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the awaiter class from TestCommon be used here to align our test "patterns"? It is used in our other tests, see DurableClientExtensions, OutboxDbContextExtensions etc.

Copy link
Contributor Author

@lasrinnil lasrinnil Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really feel its a fit in this case. If we could go over it together it would be nice 👍

}

[Fact]
public async Task
Given_PersistedActor_When_CallingIncomingMessagesWithInvalidDocumentAndBearerToken_Then_ResponseShouldBeBadRequest()
Expand Down
Loading