Skip to content

Commit

Permalink
Merge pull request #496 from DFE-Digital/mattb/fix-preview-mode
Browse files Browse the repository at this point in the history
Fix preview mode
  • Loading branch information
mattb-hippo authored Aug 7, 2024
2 parents c9dc5ee + 78d8b49 commit b8cc6cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public async Task FindByTagsAsync_Preview_Flag_Is_False_By_Default()
public async Task FindByTagsAsync_Sets_Preview_Flag()
{
// arrange
_applicationConfiguration.AzureEnvironment.Returns(ApplicationEnvironment.PreProduction);
_applicationConfiguration.ContentfulEnvironment.Returns(ApplicationEnvironment.PreProduction);

var response = Substitute.For<GraphQLResponse<SearchResourcesByTags.ResponseType>>();
Expand Down Expand Up @@ -306,6 +307,7 @@ public async Task GetByIdAsync_Preview_Flag_Is_False_By_Default()
public async Task GetByIdAsync_Sets_Preview_Flag()
{
// arrange
_applicationConfiguration.AzureEnvironment.Returns(ApplicationEnvironment.PreProduction);
_applicationConfiguration.ContentfulEnvironment.Returns(ApplicationEnvironment.PreProduction);

var collection = new ContentfulCollection<Content>
Expand Down
16 changes: 12 additions & 4 deletions Childrens-Social-Care-CPD/Configuration/ContentfulConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ public static class ContentfulConfiguration
{
public static bool IsPreviewEnabled(IApplicationConfiguration applicationConfiguration)
{
var azureEnvironment = applicationConfiguration.AzureEnvironment;
return !string.IsNullOrEmpty(azureEnvironment)
&& !string.Equals(azureEnvironment, ApplicationEnvironment.LoadTest, StringComparison.OrdinalIgnoreCase)
&& !string.Equals(applicationConfiguration.ContentfulEnvironment, azureEnvironment, StringComparison.OrdinalIgnoreCase);
string azureEnvironment = applicationConfiguration.AzureEnvironment,
contentfulEnvironment = applicationConfiguration.ContentfulEnvironment;

// return true if azure environment is pre-prod
if (string.Equals(azureEnvironment, ApplicationEnvironment.PreProduction, StringComparison.OrdinalIgnoreCase)) return true;

// return true if azure environment is dev and contentful environment is test
if (string.Equals(azureEnvironment, ApplicationEnvironment.Development, StringComparison.OrdinalIgnoreCase)
&& string.Equals(contentfulEnvironment, ApplicationEnvironment.Test, StringComparison.OrdinalIgnoreCase)) return true;

// for all other cases return false
return false;
}

public static ConfigurationManager GetContentfulConfiguration(ConfigurationManager configuration, IApplicationConfiguration applicationConfiguration)
Expand Down
6 changes: 3 additions & 3 deletions Terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ variable "cpd_contentful_env" {
default = {
Dev = "dev"
Test = "test"
Load-Test = "prod"
Pre-Prod = "prod"
Prod = "prod"
Load-Test = "master"
Pre-Prod = "master"
Prod = "master"
}
description = "Contentful Environment Name"
}
Expand Down

0 comments on commit b8cc6cc

Please sign in to comment.