-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: Added Support for timeline preview #91
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d93d60
Feat: Added Support for timeline preview
cs-raj d0d8c90
Fixing all the requied Test cases
cs-raj 8168b3d
Added Test cases for the Live Preview and removed not used imports
cs-raj 27b8616
correction
cs-raj 4c11b72
fix error
cs-raj 609172a
Fixed PR comments
cs-raj 3979010
Added newton soft json in entry.cs
cs-raj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.