Skip to content

Commit dfad702

Browse files
authored
Merge pull request #102 from contentstack/staging
Back merge - staging to dev
2 parents 82f8b30 + 52b7d84 commit dfad702

29 files changed

+414
-104
lines changed

.github/workflows/issues-jira.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Create Jira Ticket for Github Issue
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
issue-jira:
9+
runs-on: ubuntu-latest
10+
steps:
11+
12+
- name: Login to Jira
13+
uses: atlassian/gajira-login@master
14+
env:
15+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
16+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
17+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
18+
19+
- name: Create Jira Issue
20+
id: create_jira
21+
uses: atlassian/gajira-create@master
22+
with:
23+
project: ${{ secrets.JIRA_PROJECT }}
24+
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }}
25+
summary: Github | Issue | ${{ github.event.repository.name }} | ${{ github.event.issue.title }}
26+
description: |
27+
*GitHub Issue:* ${{ github.event.issue.html_url }}
28+
29+
*Description:*
30+
${{ github.event.issue.body }}
31+
fields: "${{ secrets.ISSUES_JIRA_FIELDS }}"

.github/workflows/policy-scan.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Checks the security policy and configurations
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-policy:
7+
if: github.event.repository.visibility == 'public'
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
shell: bash
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Checks for SECURITY.md policy file
15+
run: |
16+
if ! [[ -f "SECURITY.md" || -f ".github/SECURITY.md" ]]; then exit 1; fi
17+
security-license:
18+
if: github.event.repository.visibility == 'public'
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash
23+
steps:
24+
- uses: actions/checkout@master
25+
- name: Checks for License file
26+
run: |
27+
expected_license_files=("LICENSE" "LICENSE.txt" "LICENSE.md" "License.txt")
28+
license_file_found=false
29+
current_year=$(date +"%Y")
30+
31+
for license_file in "${expected_license_files[@]}"; do
32+
if [ -f "$license_file" ]; then
33+
license_file_found=true
34+
# check the license file for the current year, if not exists, exit with error
35+
if ! grep -q "$current_year" "$license_file"; then
36+
echo "License file $license_file does not contain the current year."
37+
exit 2
38+
fi
39+
break
40+
fi
41+
done
42+
43+
if [ "$license_file_found" = false ]; then
44+
echo "No license file found. Please add a license file to the repository."
45+
exit 1
46+
fi

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Version: 2.21.0
2+
#### Date: March-03-2025
3+
4+
##### Feat:
5+
- Added Support for Timeline Preview
6+
17
### Version: 2.20.0
28
#### Date: Dec-19-2024
39

Contentstack.Core.Tests/ContentTypeTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
using Xunit;
33
using Contentstack.Core.Models;
44
using System.Threading.Tasks;
5-
using Contentstack.Core.Configuration;
65
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Text.RegularExpressions;
9-
using System.Collections;
106

117
namespace Contentstack.Core.Tests
128
{

Contentstack.Core.Tests/EntryTest.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task FetchEntryByUIDPublishFallback()
7272
ContentType contenttype = client.ContentType(source);
7373
string uid = await GetUID("source1");
7474
Entry sourceEntry = contenttype.Entry(uid);
75-
await sourceEntry
75+
sourceEntry = await sourceEntry
7676
.SetLocale("ja-jp")
7777
.IncludeFallback()
7878
.Fetch<Entry>();
@@ -98,8 +98,7 @@ await sourceEntry
9898
else
9999
{
100100
Assert.True(result.Uid == sourceEntry.Uid);
101-
Assert.NotNull(result._variant);
102-
Assert.NotNull(result._variant["_uid"]);
101+
Assert.Null(result._variant);
103102
}
104103
});
105104
}
@@ -122,8 +121,7 @@ await sourceEntry
122121
else
123122
{
124123
Assert.True(result.Uid == sourceEntry.Uid);
125-
Assert.NotNull(result._variant);
126-
Assert.NotNull(result._variant["_uid"]);
124+
Assert.Null(result._variant);
127125
}
128126
});
129127
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using Xunit;
3+
using Contentstack.Core.Configuration;
4+
using System.Threading.Tasks;
5+
using System.Collections.Generic;
6+
using Newtonsoft.Json.Linq;
7+
using Newtonsoft.Json;
8+
9+
namespace Contentstack.Core.Tests
10+
{
11+
public class TestContentstackClient : ContentstackClient
12+
{
13+
public TestContentstackClient(ContentstackOptions options)
14+
: base(options)
15+
{
16+
}
17+
18+
// Override GetLivePreviewData with a hardcoded response
19+
private new async Task<JObject> GetLivePreviewData()
20+
{
21+
var mockResponse = new
22+
{
23+
entry = new
24+
{
25+
uid = "mock_entry_uid",
26+
title = "Mocked Entry",
27+
content_type_uid = "mock_content_type",
28+
status = "preview"
29+
}
30+
};
31+
string jsonResponse = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse);
32+
JObject data = JsonConvert.DeserializeObject<JObject>(jsonResponse, this.SerializerSettings);
33+
return await Task.FromResult((JObject)data["entry"]);
34+
}
35+
36+
// Public method to access the private method in tests
37+
public async Task<JObject> TestGetLivePreviewData()
38+
{
39+
return await GetLivePreviewData();
40+
}
41+
}
42+
43+
public class LivePreviewTests
44+
{
45+
ContentstackClient client = StackConfig.GetStack();
46+
47+
ContentstackClient Lpclient = StackConfig.GetLPStack();
48+
49+
private String numbersContentType = "numbers_content_type";
50+
String source = "source";
51+
52+
public double EPSILON { get; private set; }
53+
54+
[Fact]
55+
public async Task CheckLivePreviewConfigNotSet()
56+
{
57+
var LPConfig = client.GetLivePreviewConfig();
58+
Assert.False(LPConfig.Enable);
59+
Assert.Null(LPConfig.PreviewToken);
60+
Assert.Null(LPConfig.Host);
61+
}
62+
63+
[Fact]
64+
public async Task CheckLivePreviewConfigSet()
65+
{
66+
var LPConfig = Lpclient.GetLivePreviewConfig();
67+
Assert.True(LPConfig.Enable);
68+
Assert.NotEmpty(LPConfig.PreviewToken);
69+
Assert.NotEmpty(LPConfig.Host);
70+
}
71+
72+
[Fact]
73+
public async Task setQueryWithLivePreview()
74+
{
75+
Dictionary<string, string> query = new Dictionary<string, string>
76+
{
77+
{ "content_type_uid", "ct1" },
78+
{ "live_preview", "lphash" },
79+
{ "release_id", "release_id" },
80+
{ "preview_timestamp", "preview_timestamp" },
81+
{ "entry_uid", "euid" }
82+
};
83+
Lpclient.LivePreviewQueryAsync(query);
84+
var LPConfig = Lpclient.GetLivePreviewConfig();
85+
Assert.Equal(LPConfig.PreviewTimestamp, "preview_timestamp");
86+
Assert.NotEmpty(LPConfig.PreviewToken);
87+
Assert.NotEmpty(LPConfig.PreviewToken);
88+
Assert.NotEmpty(LPConfig.Host);
89+
}
90+
91+
[Fact]
92+
public async Task TestGetLivePreviewData()
93+
{
94+
// Arrange
95+
var options = new ContentstackOptions
96+
{
97+
ApiKey = "test_api_key",
98+
DeliveryToken = "test_delivery_token",
99+
Environment = "test_environment",
100+
LivePreview = new LivePreviewConfig
101+
{
102+
Enable = true,
103+
PreviewToken = "preview_token", // Replace with a valid preview token
104+
Host = "test-host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com")
105+
106+
}
107+
};
108+
109+
var client = new TestContentstackClient(options);
110+
111+
// Act
112+
var result = await client.TestGetLivePreviewData();
113+
114+
// Assert
115+
Assert.NotNull(result);
116+
Assert.Equal("mock_entry_uid", result["uid"].ToString());
117+
Assert.Equal("Mocked Entry", result["title"].ToString());
118+
}
119+
120+
}
121+
}
122+

Contentstack.Core.Tests/PluginsTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using Contentstack.Core.Models;
43
using Contentstack.Core.Tests.Models;
54
using Xunit;

Contentstack.Core.Tests/QueryTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using Xunit;
3-
using Contentstack.Core;
4-
using Contentstack.Core.Configuration;
53
using Contentstack.Core.Models;
64
using System.Threading.Tasks;
75
using System.Collections.Generic;

Contentstack.Core.Tests/StackConfig.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
2-
using Contentstack.Core;
3-
using Contentstack.Core.Models;
42
using System.Configuration;
53
using Microsoft.Extensions.Options;
4+
using Contentstack.Core.Configuration;
65

76
namespace Contentstack.Core.Tests
87
{
@@ -38,13 +37,48 @@ public static ContentstackClient GetStack()
3837
Environment = environment,
3938
Host = host,
4039
Timeout = 4500,
41-
//Proxy = new System.Net.WebProxy("http://example.com:8080")
40+
//Proxy = new System.Net.WebProxy("http://example.com:8080")
4241
};
4342

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

4645
return contentstackClient;
4746

4847
}
48+
49+
public static ContentstackClient GetLPStack()
50+
{
51+
StackConfig config = new StackConfig();
52+
if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0)
53+
{
54+
config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath);
55+
ConfigurationManager.RefreshSection("appSettings");
56+
ConfigurationManager.RefreshSection("connectionStrings");
57+
}
58+
string apiKey = ConfigurationManager.AppSettings["api_key"];
59+
string delivery_token = ConfigurationManager.AppSettings["delivery_token"];
60+
string environment = ConfigurationManager.AppSettings["environment"];
61+
string host = ConfigurationManager.AppSettings["host"];
62+
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
63+
{
64+
ApiKey = apiKey,
65+
DeliveryToken = delivery_token,
66+
Environment = environment,
67+
Host = host,
68+
Timeout = 4500,
69+
LivePreview = new LivePreviewConfig
70+
{
71+
Enable = true,
72+
PreviewToken = "preview_token", // Replace with a valid preview token
73+
Host = "test_host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com")
74+
}
75+
//Proxy = new System.Net.WebProxy("http://example.com:8080")
76+
};
77+
78+
ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));
79+
80+
return contentstackClient;
81+
82+
}
4983
}
5084
}

0 commit comments

Comments
 (0)