Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed May 24, 2024
1 parent 8ebc5bb commit 00571f1
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 31 deletions.
18 changes: 13 additions & 5 deletions backend/src/Designer/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -937,12 +937,20 @@ public IActionResult UpdateAttachmentWithTag(string org, string app, [FromQuery]
/// <returns>Empty response</returns>
[HttpGet]
[Route("api/v1/footer")]
public async Task<IActionResult> Footer(string org, string app, CancellationToken cancellationToken)
public async Task<ActionResult<Footer>> Footer(string org, string app, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken);
return Ok(footerFile);
try
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository =
_altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken);
return Ok(footerFile);
}
catch (FileNotFoundException)
{
return Ok();
}
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions backend/src/Designer/Models/FooterFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ public class FooterFile
public string Schema { get; set; }

[JsonPropertyName("footer")]
public List<FooterConfig> Footer { get; set; }
public List<Footer> Footer { get; set; }
}

public class FooterConfig
public class Footer
{
[JsonPropertyName("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Type { get; set; }

[JsonPropertyName("icon")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Icon { get; set; }

[JsonPropertyName("title")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Title { get; set; }

[JsonPropertyName("target")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Target { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ protected override void ConfigureTestServices(IServiceCollection services)
[Fact]
public async Task Get_ApplicationMetadata_Ok()
{
string expectedApplicationMetadataString = TestDataHelper.GetFileFromRepo(Org, AppV3, Developer, "App/config/applicationmetadata.json");
string expectedApplicationMetadataString = TestDataHelper.GetFileFromRepo(Org, PreviewApp, Developer, "App/config/applicationmetadata.json");
_appDevelopmentServiceMock
.Setup(rs => rs.GetAppLibVersion(It.IsAny<AltinnRepoEditingContext>()))
.Returns(NuGet.Versioning.NuGetVersion.Parse("1.0.0"));

string dataPathWithData = $"{Org}/{AppV3}/api/v1/applicationmetadata";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/applicationmetadata";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand All @@ -60,12 +60,12 @@ public async Task Get_ApplicationMetadata_Ok()
[Fact]
public async Task Get_ApplicationMetadata_With_V8_Altinn_Nuget_Version_Ok()
{
string expectedApplicationMetadataString = TestDataHelper.GetFileFromRepo(Org, AppV3, Developer, "App/config/applicationmetadata.json");
string expectedApplicationMetadataString = TestDataHelper.GetFileFromRepo(Org, PreviewApp, Developer, "App/config/applicationmetadata.json");
_appDevelopmentServiceMock
.Setup(rs => rs.GetAppLibVersion(It.IsAny<AltinnRepoEditingContext>()))
.Returns(NuGet.Versioning.NuGetVersion.Parse("8.0.0"));

string dataPathWithData = $"{Org}/{AppV3}/api/v1/applicationmetadata";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/applicationmetadata";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ApplicationSettingsTests(WebApplicationFactory<Program> factory) : base(f
[Fact]
public async Task Get_ApplicationSettings_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/v1/applicationsettings";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/applicationsettings";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public DatamodelTests(WebApplicationFactory<Program> factory) : base(factory)
[Fact]
public async Task Get_Datamodel_Ok()
{
string expectedDatamodel = TestDataHelper.GetFileFromRepo(Org, AppV3, Developer, "App/models/custom-dm-name.schema.json");
string expectedDatamodel = TestDataHelper.GetFileFromRepo(Org, PreviewApp, Developer, "App/models/custom-dm-name.schema.json");

string dataPathWithData = $"{Org}/{AppV3}/api/jsonschema/custom-dm-name";
string dataPathWithData = $"{Org}/{PreviewApp}/api/jsonschema/custom-dm-name";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public GetApplicationLanguagesTests(WebApplicationFactory<Program> factory) : ba
[Fact]
public async Task Get_ApplicationLanguages_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/v1/applicationlanguages";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/applicationlanguages";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Models;
using Designer.Tests.Utils;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using SharedResources.Tests;
using Xunit;

namespace Designer.Tests.Controllers.PreviewController
{
public class GetFooterTests : PreviewControllerTestsBase<GetFooterTests>, IClassFixture<WebApplicationFactory<Program>>
{
public GetFooterTests(WebApplicationFactory<Program> factory) : base(factory)
{
}

[Fact]
public async Task Get_Footer_Exists_Ok()
{
string expectedFooter = TestDataHelper.GetFileFromRepo(Org, AppV4, Developer, "App/ui/footer.json");
FooterFile actualFooter = JsonSerializer.Deserialize<FooterFile>(expectedFooter);

string dataPathWithData = $"{Org}/{AppV4}/api/v1/footer";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

string responseString = await response.Content.ReadAsStringAsync();
FooterFile responseFooter = JsonSerializer.Deserialize<FooterFile>(responseString);

responseFooter.Footer.Should().BeEquivalentTo(actualFooter.Footer);
}

[Fact]
public async Task Get_Footer_Non_Existing_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/v1/footer";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public GetFormDataTests(WebApplicationFactory<Program> factory) : base(factory)
[Fact]
public async Task Get_FormData_Ok()
{
string expectedFormData = TestDataHelper.GetFileFromRepo(Org, AppV3, Developer, "App/models/custom-dm-name.schema.json");
string expectedFormData = TestDataHelper.GetFileFromRepo(Org, PreviewApp, Developer, "App/models/custom-dm-name.schema.json");

string dataPathWithData = $"{Org}/{AppV3}/instances/{PartyId}/{InstanceGuId}/data/test-datatask-id";
string dataPathWithData = $"{Org}/{PreviewApp}/instances/{PartyId}/{InstanceGuId}/data/test-datatask-id";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);
httpRequestMessage.Headers.Referrer = new Uri($"{MockedReferrerUrl}?org={Org}&app={AppV3}&selectedLayoutSet=");
httpRequestMessage.Headers.Referrer = new Uri($"{MockedReferrerUrl}?org={Org}&app={PreviewApp}&selectedLayoutSet=");

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public GetFormLayoutsTests(WebApplicationFactory<Program> factory) : base(factor
[Fact]
public async Task Get_FormLayouts_Ok()
{
string expectedFormLayout = TestDataHelper.GetFileFromRepo(Org, AppV3, Developer, "App/ui/layouts/layout.json");
string expectedFormLayout = TestDataHelper.GetFileFromRepo(Org, PreviewApp, Developer, "App/ui/layouts/layout.json");
string expectedFormLayouts = @"{""layout"": " + expectedFormLayout + "}";

string dataPathWithData = $"{Org}/{AppV3}/api/resource/FormLayout.json";
string dataPathWithData = $"{Org}/{PreviewApp}/api/resource/FormLayout.json";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public GetImageTests(WebApplicationFactory<Program> factory) : base(factory)
[Fact]
public async Task Get_Image_From_Wwww_Root_Folder_Ok()
{
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, AppV3, Developer, "App/wwwroot/AltinnD-logo.svg");
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, PreviewApp, Developer, "App/wwwroot/AltinnD-logo.svg");

string dataPathWithData = $"{Org}/{AppV3}/AltinnD-logo.svg";
string dataPathWithData = $"{Org}/{PreviewApp}/AltinnD-logo.svg";

using HttpResponseMessage response = await HttpClient.GetAsync(dataPathWithData);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -35,9 +35,9 @@ public async Task Get_Image_From_Wwww_Root_Folder_Ok()
[Fact]
public async Task Get_Image_From_Sub_Folder_Ok()
{
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, AppV3, Developer, "App/wwwroot/images/AltinnD-logo.svg");
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, PreviewApp, Developer, "App/wwwroot/images/AltinnD-logo.svg");

string dataPathWithData = $"{Org}/{AppV3}/images/AltinnD-logo.svg";
string dataPathWithData = $"{Org}/{PreviewApp}/images/AltinnD-logo.svg";

using HttpResponseMessage response = await HttpClient.GetAsync(dataPathWithData);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -50,9 +50,9 @@ public async Task Get_Image_From_Sub_Folder_Ok()
[Fact]
public async Task Get_Image_From_Sub_Sub_Folder_Ok()
{
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, AppV3, Developer, "App/wwwroot/images/subImagesFolder/AltinnD-logo.svg");
byte[] expectedImageData = TestDataHelper.GetFileAsByteArrayFromRepo(Org, PreviewApp, Developer, "App/wwwroot/images/subImagesFolder/AltinnD-logo.svg");

string dataPathWithData = $"{Org}/{AppV3}/images/subImagesFolder/AltinnD-logo.svg";
string dataPathWithData = $"{Org}/{PreviewApp}/images/subImagesFolder/AltinnD-logo.svg";

using HttpResponseMessage response = await HttpClient.GetAsync(dataPathWithData);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GetOptionsTests(WebApplicationFactory<Program> factory) : base(factory)
[Fact]
public async Task Get_Options_when_options_exists_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/options/test-options";
string dataPathWithData = $"{Org}/{PreviewApp}/api/options/test-options";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task Get_RuleConfiguration_Ok()
[Fact]
public async Task Get_RuleConfiguration_NoContent()
{
string dataPathWithData = $"{Org}/{AppV3}/api/resource/RuleConfiguration.json";
string dataPathWithData = $"{Org}/{PreviewApp}/api/resource/RuleConfiguration.json";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LanguageTests(WebApplicationFactory<Program> factory) : base(factory)
[Fact]
public async Task Get_Text_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/v1/texts/nb";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/texts/nb";

using HttpResponseMessage response = await HttpClient.GetAsync(dataPathWithData);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class PreviewControllerTestsBase<TTestClass> : DisagnerEndpointsTestsBase
where TTestClass : class
{
protected const string Org = "ttd";
protected const string AppV3 = "preview-app";
protected const string AppV3 = "app-without-layoutsets";
protected const string AppV4 = "app-with-layoutsets";
protected const string PreviewApp = "preview-app";
protected const string Developer = "testUser";
protected const string LayoutSetName = "layoutSet1";
protected const string LayoutSetName2 = "layoutSet2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TextResourcesTests(WebApplicationFactory<Program> factory) : base(factory
[Fact]
public async Task Get_TextResources_Ok()
{
string dataPathWithData = $"{Org}/{AppV3}/api/v1/textresources";
string dataPathWithData = $"{Org}/{PreviewApp}/api/v1/textresources";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, dataPathWithData);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/footer.schema.v1.json",
"footer": [
{
"type": "Link",
"icon": "information",
"title": "general.accessibility",
"target": "general.accessibility_url"
}
]
}

0 comments on commit 00571f1

Please sign in to comment.