-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c464382
commit ebc811f
Showing
8 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...nd/tests/Designer.Tests/Controllers/AppScopesController/GetScopesFromMaskinPortenTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
using Altinn.Studio.Designer.Models.Dto; | ||
using Designer.Tests.Controllers.AppScopesController.Base; | ||
using Designer.Tests.Controllers.AppScopesController.Utils; | ||
using Designer.Tests.Fixtures; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Controllers.AppScopesController; | ||
|
||
public class GetScopesFromMaskinPortenTests : AppScopesControllerTestsBase<GetAppScopesTests>, IClassFixture<WebApplicationFactory<Program>>, IClassFixture<MockServerFixture> | ||
{ | ||
private static string VersionPrefix(string org, string repository) => | ||
$"/designer/api/{org}/{repository}/app-scopes/maskinporten"; | ||
|
||
private readonly MockServerFixture _mockServerFixture; | ||
|
||
public GetScopesFromMaskinPortenTests(WebApplicationFactory<Program> factory, DesignerDbFixture designerDbFixture, MockServerFixture mockServerFixture) : base(factory, designerDbFixture) | ||
{ | ||
_mockServerFixture = mockServerFixture; | ||
JsonConfigOverrides.Add( | ||
$$""" | ||
{ | ||
"MaskinPortenHttpClientSettings" : { | ||
"BaseUrl": "{{mockServerFixture.MockApi.Url}}" | ||
} | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(TestData))] | ||
public async Task GetScopesFromMaskinPortens_Should_ReturnOk(string org, string app, string maskinPortenResponse) | ||
{ | ||
_mockServerFixture.PrepareMaskinPortenScopesResponse(maskinPortenResponse); | ||
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get | ||
, VersionPrefix(org, app)); | ||
|
||
using var response = await HttpClient.SendAsync(httpRequestMessage); | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
AppScopesResponse repsponseContent = await response.Content.ReadAsAsync<AppScopesResponse>(); | ||
JsonArray array = (JsonArray)JsonNode.Parse(maskinPortenResponse); | ||
repsponseContent.Scopes.Count.Should().Be(array.Count); | ||
} | ||
|
||
|
||
public static IEnumerable<object[]> TestData() | ||
{ | ||
yield return ["ttd", | ||
"non-existing-app", | ||
$@"[ | ||
{{ | ||
""scope"": ""altinn:demo.torsdag"", | ||
""state"": ""APPROVED"", | ||
""created"": ""2024-10-24T08:40:23Z"", | ||
""description"": ""Dette er en test"", | ||
""active"": true, | ||
""consumer_orgno"": ""310461598"", | ||
""last_updated"": ""2024-10-24T08:40:23Z"", | ||
""owner_orgno"": ""991825827"", | ||
""allowed_integration_types"": [ | ||
""maskinporten"" | ||
] | ||
}}, | ||
{{ | ||
""scope"": ""altinn:mirko.dan.test"", | ||
""state"": ""APPROVED"", | ||
""created"": ""2024-10-28T11:10:49Z"", | ||
""description"": ""Dette er bare en test for Altinn Studio integrasjon"", | ||
""active"": true, | ||
""consumer_orgno"": ""310461598"", | ||
""last_updated"": ""2024-10-28T11:10:49Z"", | ||
""owner_orgno"": ""991825827"", | ||
""allowed_integration_types"": [ | ||
""maskinporten"" | ||
] | ||
}} | ||
]" | ||
]; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../Designer.Tests/Controllers/AppScopesController/Utils/MaskinPortenMockServerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Net.Mime; | ||
using Designer.Tests.Fixtures; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
|
||
namespace Designer.Tests.Controllers.AppScopesController.Utils; | ||
|
||
public static class MaskinPortenMockServerExtensions | ||
{ | ||
public static void PrepareMaskinPortenScopesResponse(this MockServerFixture mockServerFixture, string responseJson) | ||
{ | ||
var request = Request.Create() | ||
.UsingGet() | ||
.WithPath("/datasharing/consumer/scope/access"); | ||
|
||
var response = Response.Create() | ||
.WithStatusCode(200) | ||
.WithHeader("content-type", MediaTypeNames.Application.Json) | ||
.WithBody(responseJson); | ||
|
||
mockServerFixture.MockApi.Given(request) | ||
.RespondWith( | ||
response | ||
); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
backend/tests/Designer.Tests/Fixtures/MockServerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Threading.Tasks; | ||
using WireMock.Server; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Fixtures; | ||
|
||
public class MockServerFixture : IAsyncLifetime | ||
{ | ||
public WireMockServer MockApi; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
await Task.CompletedTask; | ||
int availablePort = TestUrlsProvider.GetRandomAvailablePort(); | ||
MockApi = WireMockServer.Start(availablePort); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await Task.CompletedTask; | ||
MockApi?.Stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters