Skip to content

Commit

Permalink
Merge pull request #28 from philips-software/feat/18-ignore-unknown-f…
Browse files Browse the repository at this point in the history
…rontmatter-options
  • Loading branch information
Brend-Smits authored Apr 6, 2023
2 parents e3cb22e + e19066b commit 8056bfd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
9 changes: 6 additions & 3 deletions Action/Services/ConfigureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ public Settings OverrideSettings(Settings originalSettings, Settings settingsToR
if (settingsToReplaceWith.ContentFormat != null)
originalSettings.ContentFormat = settingsToReplaceWith.ContentFormat;

if (settingsToReplaceWith.Tags.Any()) originalSettings.Tags = settingsToReplaceWith.Tags;
if (settingsToReplaceWith.Tags?.Any() == true)
originalSettings.Tags = settingsToReplaceWith.Tags;

if (settingsToReplaceWith.License != null) originalSettings.License = settingsToReplaceWith.License;
if (settingsToReplaceWith.License != null)
originalSettings.License = settingsToReplaceWith.License;

if (settingsToReplaceWith.PublishStatus != null)
originalSettings.PublishStatus = settingsToReplaceWith.PublishStatus;

if (settingsToReplaceWith.Title != null) originalSettings.Title = settingsToReplaceWith.Title;
if (settingsToReplaceWith.Title != null)
originalSettings.Title = settingsToReplaceWith.Title;

return originalSettings;
}
Expand Down
1 change: 1 addition & 0 deletions Action/Services/MediumService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private async Task ParseFrontmatter(string content)
// deserialize the yaml block into a custom type
IDeserializer deserializer = new DeserializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
Settings metadata = deserializer.Deserialize<Settings>(yaml);
_settings = _configureService.OverrideSettings(_settings, metadata);
Expand Down
32 changes: 32 additions & 0 deletions Tests/MediumServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ public async Task SubmitNewContentAsync_WithPublication_ShouldCreatePostAsPublic
Assert.AreEqual("some-content", post.Title);
}

[Test]
public async Task
SubmitNewContentAsync_WithUnusedAttributesInFrontmatter_ShouldIgnoreUnusedfrontmatterAndCreatePostAsPublication()
{
IConfigureService configureService = new ConfigureService();
string[] args =
{
"-t", "validToken", "-e", "some-title", "-a", "tag", "-o", "markdown", "-n",
"Philips Experience Design Blog", "--file", "test-with-unused-frontmatter.md", "--parse-frontmatter", "true"
};
Settings configuredSettings = configureService.ConfigureApplication(args);

Mock<HttpMessageHandler> handlerMock =
MockMediumCall(_successfullCurrentMediumUserHttpResponse, "https://api.medium.com/v1/me");

handlerMock = MockMediumCall(handlerMock, _successfullGetPublicationsFromMediumUserHttpResponse,
"https://api.medium.com/v1/users/1840a7bacce6d851c032cfb7de25919c500506726fe203254bb43b629755919b5/publications");

handlerMock = MockMediumCall(handlerMock, new HttpResponseMessage
{
StatusCode = HttpStatusCode.Created,
Content = new StringContent(
"{ \"data\": {\n \"id\": \"e855b9f3048a\",\n \"title\": \"some-content\",\n \"authorId\": \"1620245129e9d0ed50b8ebf3416552bed81e7100b561f1ab0f92f071739bc6033\",\n \"url\": \"https://medium.com/@philips/some-content-e855b9f3048a\",\n \"canonicalUrl\": \"\",\n \"publishStatus\": \"\",\n \"publishedAt\": 1655898280492,\n \"license\": \"\",\n \"licenseUrl\": \"https://policy.medium.com/medium-terms-of-service-9db0094a1e0f\",\n \"tags\": [],\n \"publicationId\": \"536bc4016034\"\n }}")
}, "https://api.medium.com/v1/publications/28ccdb7d334d/posts");

MediumService service = new(configuredSettings, new HttpClient(handlerMock.Object));

Assert.DoesNotThrowAsync(async () => await service.SubmitNewContentAsync());
MediumCreatedPost post = await service.SubmitNewContentAsync();
Assert.AreEqual("some-content", post.Title);
}

[Test]
public void SetWorkflowOutputs_WithMediumPost_ShouldSetOutputs()
{
Expand Down
17 changes: 11 additions & 6 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0"/>
<PackageReference Include="AutoFixture" Version="4.17.0"/>
<PackageReference Include="Moq" Version="4.18.1"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="AutoFixture" Version="4.17.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Action\PostMediumGitHubAction.csproj"/>
<ProjectReference Include="..\Action\PostMediumGitHubAction.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="test-with-unused-frontmatter.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions Tests/test-with-unused-frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Hello World"
date: 2023-03-05T16:44:36+08:00
publishdate: 2023-03-20T04:44:36+08:00
tags: ['helloworld']
comments: true
draft: true
---
Hello world

0 comments on commit 8056bfd

Please sign in to comment.