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

DX | 17-03-2025 | Release #94

Merged
merged 10 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ jobs:
security-sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
dotnet-version: "7.0.x"
- name: Run Dotnet Restore
run: |
dotnet restore
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/dotnet@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --fail-on=all
args: --file=Contentstack.Core/obj/project.assets.json --fail-on=all
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version: 2.21.0
#### Date: March-03-2025

##### Feat:
- Added Support for Timeline Preview

### Version: 2.20.0
#### Date: Dec-19-2024

Expand Down
4 changes: 0 additions & 4 deletions Contentstack.Core.Tests/ContentTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
using Xunit;
using Contentstack.Core.Models;
using System.Threading.Tasks;
using Contentstack.Core.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections;

namespace Contentstack.Core.Tests
{
Expand Down
8 changes: 3 additions & 5 deletions Contentstack.Core.Tests/EntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task FetchEntryByUIDPublishFallback()
ContentType contenttype = client.ContentType(source);
string uid = await GetUID("source1");
Entry sourceEntry = contenttype.Entry(uid);
await sourceEntry
sourceEntry = await sourceEntry
.SetLocale("ja-jp")
.IncludeFallback()
.Fetch<Entry>();
Expand All @@ -98,8 +98,7 @@ await sourceEntry
else
{
Assert.True(result.Uid == sourceEntry.Uid);
Assert.NotNull(result._variant);
Assert.NotNull(result._variant["_uid"]);
Assert.Null(result._variant);
}
});
}
Expand All @@ -122,8 +121,7 @@ await sourceEntry
else
{
Assert.True(result.Uid == sourceEntry.Uid);
Assert.NotNull(result._variant);
Assert.NotNull(result._variant["_uid"]);
Assert.Null(result._variant);
}
});
}
Expand Down
122 changes: 122 additions & 0 deletions Contentstack.Core.Tests/LivePreviewTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using Xunit;
using Contentstack.Core.Configuration;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace Contentstack.Core.Tests
{
public class TestContentstackClient : ContentstackClient
{
public TestContentstackClient(ContentstackOptions options)
: base(options)
{
}

// Override GetLivePreviewData with a hardcoded response
private new async Task<JObject> GetLivePreviewData()
{
var mockResponse = new
{
entry = new
{
uid = "mock_entry_uid",
title = "Mocked Entry",
content_type_uid = "mock_content_type",
status = "preview"
}
};
string jsonResponse = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse);
JObject data = JsonConvert.DeserializeObject<JObject>(jsonResponse, this.SerializerSettings);
return await Task.FromResult((JObject)data["entry"]);
}

// Public method to access the private method in tests
public async Task<JObject> TestGetLivePreviewData()
{
return await GetLivePreviewData();
}
}

public class LivePreviewTests
{
ContentstackClient client = StackConfig.GetStack();

ContentstackClient Lpclient = StackConfig.GetLPStack();

private String numbersContentType = "numbers_content_type";
String source = "source";

public double EPSILON { get; private set; }

[Fact]
public async Task CheckLivePreviewConfigNotSet()
{
var LPConfig = client.GetLivePreviewConfig();
Assert.False(LPConfig.Enable);
Assert.Null(LPConfig.PreviewToken);
Assert.Null(LPConfig.Host);
}

[Fact]
public async Task CheckLivePreviewConfigSet()
{
var LPConfig = Lpclient.GetLivePreviewConfig();
Assert.True(LPConfig.Enable);
Assert.NotEmpty(LPConfig.PreviewToken);
Assert.NotEmpty(LPConfig.Host);
}

[Fact]
public async Task setQueryWithLivePreview()
{
Dictionary<string, string> query = new Dictionary<string, string>
{
{ "content_type_uid", "ct1" },
{ "live_preview", "lphash" },
{ "release_id", "release_id" },
{ "preview_timestamp", "preview_timestamp" },
{ "entry_uid", "euid" }
};
Lpclient.LivePreviewQueryAsync(query);
var LPConfig = Lpclient.GetLivePreviewConfig();
Assert.Equal(LPConfig.PreviewTimestamp, "preview_timestamp");
Assert.NotEmpty(LPConfig.PreviewToken);
Assert.NotEmpty(LPConfig.PreviewToken);
Assert.NotEmpty(LPConfig.Host);
}

[Fact]
public async Task TestGetLivePreviewData()
{
// Arrange
var options = new ContentstackOptions
{
ApiKey = "test_api_key",
DeliveryToken = "test_delivery_token",
Environment = "test_environment",
LivePreview = new LivePreviewConfig
{
Enable = true,
PreviewToken = "preview_token", // Replace with a valid preview token
Host = "test-host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com")

}
};

var client = new TestContentstackClient(options);

// Act
var result = await client.TestGetLivePreviewData();

// Assert
Assert.NotNull(result);
Assert.Equal("mock_entry_uid", result["uid"].ToString());
Assert.Equal("Mocked Entry", result["title"].ToString());
}

}
}

3 changes: 1 addition & 2 deletions Contentstack.Core.Tests/PluginsTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Contentstack.Core.Models;
using Contentstack.Core.Tests.Models;
using Xunit;
Expand Down
2 changes: 0 additions & 2 deletions Contentstack.Core.Tests/QueryTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using Xunit;
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using System.Threading.Tasks;
using System.Collections.Generic;
Expand Down
40 changes: 37 additions & 3 deletions Contentstack.Core.Tests/StackConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Contentstack.Core;
using Contentstack.Core.Models;
using System.Configuration;
using Microsoft.Extensions.Options;
using Contentstack.Core.Configuration;

namespace Contentstack.Core.Tests
{
Expand Down Expand Up @@ -38,13 +37,48 @@ public static ContentstackClient GetStack()
Environment = environment,
Host = host,
Timeout = 4500,
//Proxy = new System.Net.WebProxy("http://example.com:8080")
//Proxy = new System.Net.WebProxy("http://example.com:8080")
};

ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));

return contentstackClient;

}

public static ContentstackClient GetLPStack()
{
StackConfig config = new StackConfig();
if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0)
{
config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection("connectionStrings");
}
string apiKey = ConfigurationManager.AppSettings["api_key"];
string delivery_token = ConfigurationManager.AppSettings["delivery_token"];
string environment = ConfigurationManager.AppSettings["environment"];
string host = ConfigurationManager.AppSettings["host"];
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
{
ApiKey = apiKey,
DeliveryToken = delivery_token,
Environment = environment,
Host = host,
Timeout = 4500,
LivePreview = new LivePreviewConfig
{
Enable = true,
PreviewToken = "preview_token", // Replace with a valid preview token
Host = "test_host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com")
}
//Proxy = new System.Net.WebProxy("http://example.com:8080")
};

ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));

return contentstackClient;

}
}
}
22 changes: 8 additions & 14 deletions Contentstack.Core.Tests/TaxonomyTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using System;
using Xunit;
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using Contentstack.Core.Tests.Models;
using Newtonsoft.Json.Linq;
using System.Reflection.PortableExecutable;

namespace Contentstack.Core.Tests
{
Expand Down Expand Up @@ -39,7 +33,7 @@ public async Task TaxonomyExists()
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
IsTrue = data.Get("_content_type_uid") != null;
if (!IsTrue)
{
break;
Expand Down Expand Up @@ -69,7 +63,7 @@ public async Task TaxonomyEqualAndBelow()
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
IsTrue = data.Get("_content_type_uid") != null;
if (!IsTrue)
{
break;
Expand Down Expand Up @@ -99,7 +93,7 @@ public async Task TaxonomyBelow()
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
IsTrue = data.Get("_content_type_uid") != null;
if (!IsTrue)
{
break;
Expand All @@ -118,7 +112,7 @@ public async Task TaxonomyEqualAndAbove()
{
// Description: Taxonomy EqualAndAbove - Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)
Taxonomy query = client.Taxonomies();
query.EqualAndAbove("taxonomies.one", "term_one");
query.EqualAndAbove("taxonomies.one", "term_one_child");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Expand All @@ -129,7 +123,7 @@ public async Task TaxonomyEqualAndAbove()
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
IsTrue = data.Get("_content_type_uid") != null;
if (!IsTrue)
{
break;
Expand All @@ -148,7 +142,7 @@ public async Task TaxonomyAbove()
{
// Description: Taxonomy Above - Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)
Taxonomy query = client.Taxonomies();
query.Above("taxonomies.one", "term_one");
query = query.Above("taxonomies.one", "term_one_child");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Expand All @@ -157,9 +151,9 @@ public async Task TaxonomyAbove()
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
foreach (var data in result.Items)
{
IsTrue = data.GetContentType() != null;
IsTrue = data.Get("_content_type_uid") != null;
if (!IsTrue)
{
break;
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class Config
private string _Port;
private string _Version;
private string _Environment;
private string _Branch;
private string _Branch="main";
private int _Timeout;
private WebProxy _proxy;
#endregion
Expand Down
6 changes: 3 additions & 3 deletions Contentstack.Core/Configuration/LivePreviewConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;

namespace Contentstack.Core.Configuration
{
Expand All @@ -14,5 +12,7 @@ public class LivePreviewConfig
internal string ContentTypeUID { get; set; }
internal string EntryUID { get; set; }
internal JObject PreviewResponse { get; set; }
public string ReleaseId {get; set;}
public string PreviewTimestamp {get; set;}
}
}
Loading
Loading