Skip to content

Commit

Permalink
Fix/delete systems (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyeng authored Dec 11, 2024
1 parent 7be2a21 commit 2f054c7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Net;
using System.Text.Json;
using Altinn.Platform.Authentication.SystemIntegrationTests.Domain;
using Altinn.Platform.Authentication.SystemIntegrationTests.Tests;
using Altinn.Platform.Authentication.SystemIntegrationTests.Utils;
using Xunit;
Expand Down Expand Up @@ -30,4 +32,24 @@ public async Task<HttpResponseMessage> PostSystem(string requestBody, string tok

return response;
}

public async Task<List<SystemDto>> GetSystemsAsync(string token)
{
var response = await _platformClient.GetAsync("v1/systemregister/", token);

// Assert the response status is OK
Assert.True(HttpStatusCode.OK == response.StatusCode,
$"{response.StatusCode} {await response.Content.ReadAsStringAsync()}");

// Deserialize the JSON content to a list of SystemDto
var jsonContent = await response.Content.ReadAsStringAsync();
var systems = JsonSerializer.Deserialize<List<SystemDto>>(jsonContent, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true // Allows matching JSON properties in different casing
});

return systems ?? new List<SystemDto>();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Altinn.Platform.Authentication.SystemIntegrationTests.Domain;

// DTO Classes
public class SystemDto
{
public string SystemId { get; set; }

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string SystemVendorOrgNumber { get; set; }

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemVendorOrgNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string SystemVendorOrgName { get; set; }

Check warning on line 8 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'SystemVendorOrgName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'SystemVendorOrgName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'SystemVendorOrgName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemVendorOrgName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'SystemVendorOrgName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class SystemsDto
{
public List<SystemDto> Systems { get; set; }

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for at22

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in test/Altinn.Platform.Authentication.SystemIntegrationTests/Domain/SystemDto.cs

View workflow job for this annotation

GitHub Actions / Run Tests for tt02

Non-nullable property 'Systems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task GetSystemRegisterReturns200Ok()
// Act
var response =
await _platformClient.GetAsync("v1/systemregister", maskinportenToken);


// Assert
Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
Expand Down Expand Up @@ -183,4 +183,25 @@ await _platformClient.GetAsync($"v1/systemregister/{teststate.SystemId}",
//More asserts should be added, but there are known bugs right now regarding validation of rights
Assert.Equal(HttpStatusCode.OK, get.StatusCode);
}

[Fact]
public async Task DeleteEverySystemCreatedByEndToEndTests()
{
var maskinportenToken = await _platformClient.GetMaskinportenToken();
var systemIds = await _systemRegisterClient.GetSystemsAsync(maskinportenToken);

var idsToDelete = systemIds.FindAll(system => system.SystemVendorOrgNumber.Equals(_platformClient.EnvironmentHelper.Vendor));

foreach (var systemDto in idsToDelete)
{
_outputHelper.WriteLine("Attempting to delete system with id: " + systemDto.SystemId);
// Act
var respons = await _platformClient.Delete(
$"v1/systemregister/vendor/{systemDto.SystemId}", maskinportenToken);

// Assert
Assert.Equal(HttpStatusCode.OK, respons.StatusCode);
}

}
}

0 comments on commit 2f054c7

Please sign in to comment.