Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Contentful graphql API support #307

Merged
merged 12 commits into from
Oct 30, 2023
2 changes: 1 addition & 1 deletion .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
/o:"dfe-digital" \
/d:sonar.qualitygate.wait=true \
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs" \
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs,**/GraphQL/Queries/*" \
/d:sonar.test.exclusions="Childrens-Social-Care-CPD-Tests/**/*" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Childrens_Social_Care_CPD.Configuration;
using Contentful.Core.Models.Management;
using FluentAssertions;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void Returns_AzureEnvironment_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AzureEnvironment;
var actual = sut.AzureEnvironment.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -60,7 +61,7 @@ public void Returns_ClarityProjectId_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ClarityProjectId;
var actual = sut.ClarityProjectId.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -75,7 +76,7 @@ public void Returns_ContentfulDeliveryApiKey_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulDeliveryApiKey;
var actual = sut.ContentfulDeliveryApiKey.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -89,12 +90,27 @@ public void Returns_ContentfulEnvironment_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulEnvironment;
var actual = sut.ContentfulEnvironment.Value;

// assert
actual.Should().Be(Value);
}

[Test]
public void Returns_ContentfulGraphqlConnectionString_Value()
{
// arrange
Environment.SetEnvironmentVariable("CPD_SPACE_ID", Value);
Environment.SetEnvironmentVariable("CPD_CONTENTFUL_ENVIRONMENT", Value);
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulGraphqlConnectionString.Value;

// assert
actual.Should().Be($"https://graphql.contentful.com/content/v1/spaces/{Value}/environments/{Value}");
}

[Test]
public void Returns_ContentfulPreviewHost_Value()
{
Expand All @@ -103,7 +119,7 @@ public void Returns_ContentfulPreviewHost_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulPreviewHost;
var actual = sut.ContentfulPreviewHost.Value;

// assert
actual.Should().Be(value);
Expand All @@ -117,7 +133,7 @@ public void Returns_ContentfulPreviewId_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulPreviewId;
var actual = sut.ContentfulPreviewId.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -131,7 +147,7 @@ public void Returns_ContentfulSpaceId_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulSpaceId;
var actual = sut.ContentfulSpaceId.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -145,7 +161,7 @@ public void Returns_GoogleTagManagerKey_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.GoogleTagManagerKey;
var actual = sut.GoogleTagManagerKey.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -159,7 +175,7 @@ public void Returns_AppInsightsConnectionString_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AppInsightsConnectionString;
var actual = sut.AppInsightsConnectionString.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -173,7 +189,7 @@ public void Returns_GitHash_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.GitHash;
var actual = sut.GitHash.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -187,7 +203,7 @@ public void Returns_DisableSecureCookies_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.DisableSecureCookies;
var actual = sut.DisableSecureCookies.Value;

// assert
actual.Should().Be(false);
Expand All @@ -201,7 +217,7 @@ public void Returns_AppVersionEnvironment_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AppVersion;
var actual = sut.AppVersion.Value;

// assert
actual.Should().Be(Value);
Expand All @@ -215,7 +231,7 @@ public void Returns_FeaturePollInterval_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.FeaturePollingInterval;
var actual = sut.FeaturePollingInterval.Value;

// assert
actual.Should().Be(10000);
Expand All @@ -228,7 +244,7 @@ public void Returns_FeaturePollInterval_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.FeaturePollingInterval;
var actual = sut.FeaturePollingInterval.Value;

// assert
actual.Should().Be(0);
Expand All @@ -241,7 +257,7 @@ public void Returns_AzureEnvironment_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AzureEnvironment;
var actual = sut.AzureEnvironment.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -254,7 +270,7 @@ public void Returns_ClarityProjectId_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ClarityProjectId;
var actual = sut.ClarityProjectId.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -267,7 +283,7 @@ public void Returns_ContentfulDeliveryApiKey_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulDeliveryApiKey;
var actual = sut.ContentfulDeliveryApiKey.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -280,7 +296,7 @@ public void Returns_ContentfulEnvironment_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulEnvironment;
var actual = sut.ContentfulEnvironment.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -293,7 +309,7 @@ public void Returns_ContentfulPreviewId_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulPreviewId;
var actual = sut.ContentfulPreviewId.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -306,7 +322,7 @@ public void Returns_ContentfulSpaceId_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.ContentfulSpaceId;
var actual = sut.ContentfulSpaceId.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -319,7 +335,7 @@ public void Returns_GoogleTagManagerKey_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.GoogleTagManagerKey;
var actual = sut.GoogleTagManagerKey.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -332,7 +348,7 @@ public void Returns_AppInsightsConnectionString_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AppInsightsConnectionString;
var actual = sut.AppInsightsConnectionString.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -345,7 +361,7 @@ public void Returns_GitHash_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.GitHash;
var actual = sut.GitHash.Value;

// assert
actual.Should().Be(string.Empty);
Expand All @@ -358,7 +374,7 @@ public void Returns_DisableSecureCookies_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.DisableSecureCookies;
var actual = sut.DisableSecureCookies.Value;

// assert
actual.Should().Be(false);
Expand All @@ -371,7 +387,7 @@ public void Returns_AppVersionEnvironment_Default_Value()
var sut = new ApplicationConfiguration();

// act
var actual = sut.AppVersion;
var actual = sut.AppVersion.Value;

// assert
actual.Should().Be(string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,48 @@ public partial class ConfigurationInformationTests

[SetUp]
public void Setup()
{
{
_applicationConfiguration = Substitute.For<IApplicationConfiguration>();
_applicationConfiguration.AzureEnvironment.Returns("dev");
_applicationConfiguration.AzureEnvironment.Value.Returns(ApplicationEnvironment.Development);
}

[Test]
public void Required_Values_Are_Detected()
{
// arrange
_applicationConfiguration.AppVersion.Returns("foo");
_applicationConfiguration.AppVersion.Returns(new StringConfigSetting(() => "foo"));

// act
var sut = new ConfigurationInformation(_applicationConfiguration);
var actual = sut.ConfigurationInfo.Single(x => x.Name == "AppVersion");

// assert
actual.Required.Should().BeTrue();
actual.HasValue.Should().BeTrue();
actual.IsSet.Should().BeTrue();
}

[TestCase("")]
[TestCase(" ")]
[TestCase(null)]
public void Missing_Values_Are_Detected(string value)
{
// arrange
_applicationConfiguration.AppVersion.Returns(value);
_applicationConfiguration.AppVersion.Returns(new StringConfigSetting(() => value));

// act
var sut = new ConfigurationInformation(_applicationConfiguration);
var actual = sut.ConfigurationInfo.Single(x => x.Name == "AppVersion");

// assert
actual.Required.Should().BeTrue();
actual.HasValue.Should().BeFalse();
actual.IsSet.Should().BeFalse();
}

[Test]
public void Extraneous_Values_Are_Detected()
{
// arrange
_applicationConfiguration.ClarityProjectId.Returns("foo");
_applicationConfiguration.ClarityProjectId.Returns(new StringConfigSetting(() => "foo"));

// act
var sut = new ConfigurationInformation(_applicationConfiguration);
Expand All @@ -79,8 +80,8 @@ public void Sensitive_Values_Are_Obfuscated()
{
// arrange
var value = "sensitive value";
_applicationConfiguration.AzureEnvironment.Returns(ApplicationEnvironment.Production);
_applicationConfiguration.AppInsightsConnectionString.Returns(value);
_applicationConfiguration.AzureEnvironment.Returns(new StringConfigSetting(() => ApplicationEnvironment.Production));
_applicationConfiguration.AppInsightsConnectionString.Returns(new StringConfigSetting(() => value));

// act
var sut = new ConfigurationInformation(_applicationConfiguration);
Expand Down
Loading
Loading