Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Mar 1, 2024
1 parent c2aa4d9 commit 8c6ad53
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions backend/src/DataModeling/Metamodel/ModelMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Altinn.Studio.DataModeling.Metamodel
Expand Down Expand Up @@ -41,6 +42,7 @@ public class ModelMetadata
/// Gets or sets all elements for the service (<see cref="ElementMetadata"/>)
/// </summary>
[JsonProperty(PropertyName = "elements")]
[JsonPropertyName("elements")]
public Dictionary<string, ElementMetadata> Elements { get; set; } = new Dictionary<string, ElementMetadata>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public async Task<IActionResult> GetLayoutSettings(string org, string app, [From
public async Task<IActionResult> GetModelMetadata(string org, string app, [FromQuery] string layoutSetName, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
ModelMetadata modelMetadata = await _appDevelopmentService.GetModelMetadata(AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer), layoutSetName, cancellationToken);
JsonNode modelMetadata = await _appDevelopmentService.GetModelMetadata(AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer), layoutSetName, cancellationToken);
return Ok(modelMetadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.DataModeling.Metamodel;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Models;
Expand Down Expand Up @@ -141,9 +142,12 @@ public async Task<ServiceConfiguration> GetAppMetadataConfig()
public async Task<string> GetModelMetadata(string modelName)
{
string modelMetadataFileName = GetPathToModelMetadata(modelName);
JsonSerializerOptions metadataOptions = new(_jsonOptions);
metadataOptions.Converters.Add(new JsonStringEnumConverter());
if (!FileExistsByRelativePath(modelMetadataFileName))
{
return "{}";
ModelMetadata emptyModel = JsonSerializer.Deserialize<ModelMetadata>("{}", metadataOptions);
return JsonSerializer.Serialize(emptyModel);
}
return await ReadTextByRelativePathAsync(modelMetadataFileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Altinn.Studio.Designer.Services.Interfaces;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using NuGet.Versioning;
using LayoutSets = Altinn.Studio.Designer.Models.LayoutSets;
using PlatformStorageModels = Altinn.Platform.Storage.Interface.Models;
Expand Down Expand Up @@ -149,7 +148,8 @@ public async Task SaveLayoutSettings(AltinnRepoEditingContext altinnRepoEditingC
}

/// <inheritdoc />
public async Task<ModelMetadata> GetModelMetadata(AltinnRepoEditingContext altinnRepoEditingContext, string layoutSetName, CancellationToken cancellationToken = default)
public async Task<JsonNode> GetModelMetadata(AltinnRepoEditingContext altinnRepoEditingContext,
string layoutSetName, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
AltinnAppGitRepository altinnAppGitRepository =
Expand All @@ -161,7 +161,7 @@ public async Task<ModelMetadata> GetModelMetadata(AltinnRepoEditingContext altin
string taskId = await GetTaskIdBasedOnLayoutSet(altinnRepoEditingContext, layoutSetName, cancellationToken);
string modelName = GetModelName(applicationMetadata, taskId);
string fileContent = await altinnAppGitRepository.GetModelMetadata(modelName);
return JsonConvert.DeserializeObject<ModelMetadata>(fileContent);
return JsonNode.Parse(fileContent);
}

private string GetModelName(ApplicationMetadata applicationMetadata, [CanBeNull] string taskId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public interface IAppDevelopmentService
/// <param name="layoutSetName">Name of current layoutSet in ux-editor that edited layout belongs to</param>
/// <param name="cancellationToken">An <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>The service metadata for an app.</returns>
public Task<ModelMetadata> GetModelMetadata(AltinnRepoEditingContext altinnRepoEditingContext, [CanBeNull] string layoutSetName, CancellationToken cancellationToken = default);
public Task<JsonNode> GetModelMetadata(
AltinnRepoEditingContext altinnRepoEditingContext, [CanBeNull] string layoutSetName,
CancellationToken cancellationToken = default);


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public async Task GetModelMetadata_Should_Return_Empty_Model_When_No_ModelMetada
response.StatusCode.Should().Be(HttpStatusCode.OK);

string responseContent = await response.Content.ReadAsStringAsync();
string responseContentLowerCase = responseContent.ToLowerInvariant();
string expectedResposeContentLowerCase = JsonConvert
.SerializeObject(JsonConvert.DeserializeObject<ModelMetadata>("{}")).ToLowerInvariant();
responseContentLowerCase.Should().Be(expectedResposeContentLowerCase);
string expectedRespose = JsonConvert
.SerializeObject(JsonConvert.DeserializeObject<ModelMetadata>("{}"));
responseContent.Should().Be(expectedRespose);
}

private async Task<string> AddModelMetadataToRepo(string createdFolderPath, string expectedModelMetadataPath)
Expand Down

0 comments on commit 8c6ad53

Please sign in to comment.