Skip to content

Commit

Permalink
Fix tests for new support configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldirk authored and linkdotnet committed Nov 1, 2024
1 parent c4ad604 commit 42412eb
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public class SupportMeConfiguration

public bool ShowSupportMePage { get; init; }

public required string SupportMePageDescription { get; init; }
public string SupportMePageDescription { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public class ApplicationConfigurationBuilder
private bool isAboutMeEnabled;
private bool isGiscusEnabled;
private bool isDisqusEnabled;
private string? kofiToken;
private string? githubSponsorName;
private bool showReadingIndicator;
private string? patreonName;
private bool showSimilarPosts;
private string? blogBrandUrl;

Expand Down Expand Up @@ -67,29 +64,11 @@ public ApplicationConfigurationBuilder WithIsDisqusEnabled(bool isDisqusEnabled)
return this;
}

public ApplicationConfigurationBuilder WithKofiToken(string? kofiToken)
{
this.kofiToken = kofiToken;
return this;
}

public ApplicationConfigurationBuilder WithGithubSponsorName(string? githubSponsorName)
{
this.githubSponsorName = githubSponsorName;
return this;
}

public ApplicationConfigurationBuilder WithShowReadingIndicator(bool showReadingIndicator)
{
this.showReadingIndicator = showReadingIndicator;
return this;
}

public ApplicationConfigurationBuilder WithPatreonName(string? patreonName)
{
this.patreonName = patreonName;
return this;
}

public ApplicationConfigurationBuilder WithShowSimilarPosts(bool showSimilarPosts)
{
Expand All @@ -115,10 +94,7 @@ public ApplicationConfiguration Build()
IsAboutMeEnabled = isAboutMeEnabled,
IsGiscusEnabled = isGiscusEnabled,
IsDisqusEnabled = isDisqusEnabled,
KofiToken = kofiToken,
GithubSponsorName = githubSponsorName,
ShowReadingIndicator = showReadingIndicator,
PatreonName = patreonName,
ShowSimilarPosts = showSimilarPosts,
BlogBrandUrl = blogBrandUrl,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.TestUtilities;

public class SupportMeConfigurationBuilder
{
private string? kofiToken = "ABC";
private string? githubSponsorName = "linkdotnet";
private string? patreonName = "linkdotnet";
private bool showUnderBlogPost = true;
private bool showUnderIntroduction = true;
private bool showInFooter = true;
private bool showSupportMePage = true;
private string? supportMePageDescription = "Support me";

public SupportMeConfigurationBuilder WithKofiToken(string? kofiToken)
{
this.kofiToken = kofiToken;
return this;
}

public SupportMeConfigurationBuilder WithGithubSponsorName(string? githubSponsorName)
{
this.githubSponsorName = githubSponsorName;
return this;
}

public SupportMeConfigurationBuilder WithPatreonName(string? patreonName)
{
this.patreonName = patreonName;
return this;
}

public SupportMeConfigurationBuilder WithShowUnderBlogPost(bool showUnderBlogPost)
{
this.showUnderBlogPost = showUnderBlogPost;
return this;
}

public SupportMeConfigurationBuilder WithshowUnderIntroduction(bool showUnderIntroduction)
{
this.showUnderIntroduction = showUnderIntroduction;
return this;
}

public SupportMeConfigurationBuilder WithShowInFooter(bool showInFooter)
{
this.showInFooter = showInFooter;
return this;
}

public SupportMeConfigurationBuilder WithShowSupportMePage(bool showSupportMePage)
{
this.showSupportMePage = showSupportMePage;
return this;
}

public SupportMeConfigurationBuilder WithSupportMePageDescription(string? supportMePageDescription)
{
this.supportMePageDescription = supportMePageDescription;
return this;
}

public SupportMeConfiguration Build()
{
return new SupportMeConfiguration
{
KofiToken = kofiToken,
GithubSponsorName = githubSponsorName,
PatreonName = patreonName,
ShowUnderBlogPost = showUnderBlogPost,
ShowUnderIntroduction = showUnderIntroduction,
ShowInFooter = showInFooter,
ShowSupportMePage = showSupportMePage,
SupportMePageDescription = supportMePageDescription,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ public void ShouldMapFromAppConfiguration()
{ "Giscus:Category", "general" },
{ "Giscus:CategoryId", "generalid" },
{ "Disqus:Shortname", "blog" },
{ "KofiToken", "ABC" },
{ "GithubSponsorName", "linkdotnet" },
{ "ShowReadingIndicator", "true" },
{ "PatreonName", "linkdotnet" },
{ "SupportMe:KofiToken", "ABC" },
{ "SupportMe:PatreonName", "linkdotnet" },
{ "SupportMe:GithubSponsorName", "linkdotnet" },
{ "SupportMe:ShowUnderBlogPost", "true" },
{ "SupportMe:ShowUnderIntroduction", "true" },
{ "SupportMe:ShowInFooter", "true" },
{ "SupportMe:ShowSupportMePage", "true" },
{ "SupportMe:SupportMePageDescription", "Support me" },
{ "Authentication:Provider","Auth0"},
{ "Authentication:ClientId","123"},
{ "Authentication:ClientSecret","qwe"},
Expand All @@ -59,29 +64,38 @@ public void ShouldMapFromAppConfiguration()
appConfiguration.DatabaseName.ShouldBe("db");
appConfiguration.BlogPostsPerPage.ShouldBe(5);
appConfiguration.IsAboutMeEnabled.ShouldBeTrue();
appConfiguration.KofiToken.ShouldBe("ABC");
appConfiguration.GithubSponsorName.ShouldBe("linkdotnet");
appConfiguration.ShowReadingIndicator.ShouldBeTrue();
appConfiguration.PatreonName.ShouldBe("linkdotnet");
appConfiguration.IsPatreonEnabled.ShouldBeTrue();


var giscusConfiguration = new GiscusConfigurationBuilder().Build();
configuration.GetSection(GiscusConfiguration.GiscusConfigurationSection).Bind(giscusConfiguration);
giscusConfiguration.Repository.ShouldBe("repo");
giscusConfiguration.RepositoryId.ShouldBe("repoid");
giscusConfiguration.Category.ShouldBe("general");
giscusConfiguration.CategoryId.ShouldBe("generalid");

var disqusConfiguration = new DisqusConfigurationBuilder().Build();
configuration.GetSection(DisqusConfiguration.DisqusConfigurationSection).Bind(disqusConfiguration);
disqusConfiguration.Shortname.ShouldBe("blog");


var supportMeConfiguration = new SupportMeConfigurationBuilder().Build();
supportMeConfiguration.KofiToken.ShouldBe("ABC");
supportMeConfiguration.GithubSponsorName.ShouldBe("linkdotnet");
supportMeConfiguration.PatreonName.ShouldBe("linkdotnet");
supportMeConfiguration.IsPatreonEnabled.ShouldBeTrue();
supportMeConfiguration.IsKofiEnabled.ShouldBeTrue();
supportMeConfiguration.IsGithubSponsorAvailable.ShouldBeTrue();
supportMeConfiguration.ShowUnderBlogPost.ShouldBeTrue();
supportMeConfiguration.ShowUnderIntroduction.ShouldBeTrue();
supportMeConfiguration.ShowInFooter.ShouldBeTrue();
supportMeConfiguration.ShowSupportMePage.ShouldBeTrue();
supportMeConfiguration.SupportMePageDescription.ShouldBe("Support me");

var profileInformation = new ProfileInformationBuilder().Build();
configuration.GetSection(ProfileInformation.ProfileInformationSection).Bind(profileInformation);
profileInformation.Name.ShouldBe("Steven");
profileInformation.Heading.ShouldBe("Dev");
profileInformation.ProfilePictureUrl.ShouldBe("Url");

var social = new Social();
configuration.GetSection(Social.SocialSection).Bind(social);
social.GithubAccountUrl.ShouldBe("github");
Expand All @@ -96,7 +110,7 @@ public void ShouldMapFromAppConfiguration()
introduction.BackgroundUrl.ShouldBe("someurl");
introduction.ProfilePictureUrl.ShouldBe("anotherurl");
introduction.Description.ShouldBe("desc");

var authInformation = new AuthInformationBuilder().Build();
configuration.GetSection(AuthInformation.AuthInformationSection).Bind(authInformation);
authInformation.Provider.ShouldBe("Auth0");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -15,7 +16,7 @@ public class DonationSectionTests : BunitContext
public void ShouldShowKofiIfSet(string? token, bool hasComponent)
{
JSInterop.SetupVoid("myfunc", "myarg").SetVoidResult();
var appConfig = new ApplicationConfigurationBuilder()
var appConfig = new SupportMeConfigurationBuilder()
.WithKofiToken(token)
.Build();
Services.AddScoped(_ => Options.Create(appConfig));
Expand All @@ -31,7 +32,7 @@ public void ShouldShowKofiIfSet(string? token, bool hasComponent)

public void ShouldShowGithubSponsorIfSet(string? account, bool hasComponent)
{
var appConfig = new ApplicationConfigurationBuilder()
var appConfig = new SupportMeConfigurationBuilder()
.WithGithubSponsorName(account)
.Build();
Services.AddScoped(_ =>Options.Create(appConfig));
Expand All @@ -46,7 +47,7 @@ public void ShouldShowGithubSponsorIfSet(string? account, bool hasComponent)
[InlineData(null, false)]
public void ShouldShowPatreonSponsorIfSet(string? account, bool hasComponent)
{
var appConfig = new ApplicationConfigurationBuilder()
var appConfig = new SupportMeConfigurationBuilder()
.WithPatreonName(account)
.Build();
Services.AddScoped(_ => Options.Create(appConfig));
Expand All @@ -55,4 +56,4 @@ public void ShouldShowPatreonSponsorIfSet(string? account, bool hasComponent)

cut.HasComponent<Patreon>().ShouldBe(hasComponent);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

Expand All @@ -15,4 +16,4 @@ public void ShouldSetUrlCorrect()
anchor.ShouldNotBeNull();
anchor.Href.ShouldBe("https://github.com/sponsors/linkdotnet");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

Expand All @@ -12,4 +13,4 @@ public void ShouldSetToken()

((IHtmlAnchorElement)cut.Find("a")).Href.ShouldContain("https://ko-fi.com/Token");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

Expand Down

0 comments on commit 42412eb

Please sign in to comment.