Skip to content

Commit c0c4070

Browse files
Merge pull request #111 from contentstack/staging
DX | 13-06-2025 | Release
2 parents e31e1f5 + 58a96f5 commit c0c4070

File tree

11 files changed

+341
-67
lines changed

11 files changed

+341
-67
lines changed

.talismanrc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: Contentstack.Core/Internals/HttpRequestHandler.cs
6-
checksum: 93c1659f3bc7527956f0fd12db46441297fac3a4366d273bcbb3425d2351300e
6+
checksum: 94288e483056f41ff3a4c2ab652c3ce9ecb53dc0b9d4029456b34baed4f34891
77
- filename: Contentstack.Core/Models/Entry.cs
8-
checksum: a6226f755dde69be62c21737ca75569ba6ea7cb4b7a125dc460c047dbe741b9e
8+
checksum: 78a09b03b9fd6aefd0251353b2d8c70962bdfced16a6e1e28d10dc9af43da244
99
- filename: Contentstack.Core/ContentstackClient.cs
10-
checksum: 761a5d65bfa12d16641aa66e5431b2eb52b0909eff904dca5c2f607ee439cba0
10+
checksum: 687dc0a5f20037509731cfe540dcec9c3cc2b6cf50373cd183ece4f3249dc88e
1111
- filename: Contentstack.Core/Models/AssetLibrary.cs
1212
checksum: 92ff3feaf730b57c50bb8429f08dd4cddedb42cd89f2507e9746f8237b65fb11
1313
- filename: Contentstack.Core/Models/Asset.cs
@@ -18,11 +18,5 @@ fileignoreconfig:
1818
checksum: 751a725d94eff7d845bb22a5ce80a5529bb62971373de39288149fff3d024930
1919
- filename: .github/workflows/nuget-publish.yml
2020
checksum: 53ba4ce874c4d2362ad00deb23f5a6ec219318860352f997b945e9161a580651
21-
- filename: Contentstack.Core/Models/ContentType.cs
22-
checksum: 53e3b8330183445d100b32c545073f281b869ee238514c7ab8c9a4500a140166
23-
- filename: Contentstack.Core.Tests/ContentTypeTest.cs
24-
checksum: a2549638af21492d5a299dce35a2994ec4721b211af6956b955602d7065c47dc
25-
- filename: Contentstack.Core/Models/GlobalFieldQuery.cs
26-
checksum: 16fb3c5fb4de2b686f338b0666c7c86c3d37f2a276f85698a59a1ac1a02d359d
27-
- filename: Contentstack.Core/Models/GlobalField.cs
28-
checksum: 49cc6ec8b55408a3e71ba19551dbe01709ec70bc673fae21c280a1f74968e395
21+
- filename: Contentstack.Core.Tests/ContentstackClientTest.cs
22+
checksum: b63897181a8cb5993d1305248cfc3e711c4039b5677b6c1e4e2a639e4ecb391b

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Version: 2.22.1
2+
#### Date: June-13-2025
3+
4+
##### Fix:
5+
- Fixed Timeline issue of Entry not getting updated
6+
17
### Version: 2.22.0
28
#### Date: March-03-2025
39

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
// Contentstack.Core/ContentstackClientTest.cs
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Contentstack.Core.Configuration;
8+
9+
namespace Contentstack.Core.Tests
10+
{
11+
public class ContentstackClientTest
12+
{
13+
private ContentstackClient CreateClient()
14+
{
15+
var options = new ContentstackOptions()
16+
{
17+
ApiKey = "api_key",
18+
DeliveryToken = "delivery_token",
19+
Environment = "environment",
20+
Version = "1.2.3",
21+
LivePreview = new LivePreviewConfig()
22+
{
23+
Enable = true,
24+
Host = "https://preview.contentstack.com",
25+
ReleaseId = "rid",
26+
PreviewTimestamp = "ts",
27+
PreviewToken = "pt"
28+
29+
}
30+
};
31+
return new ContentstackClient(options);
32+
}
33+
34+
private string GetPrivateField(ContentstackClient client, string fieldName)
35+
{
36+
var field = typeof(ContentstackClient).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
37+
return (string)field.GetValue(client);
38+
}
39+
40+
[Fact]
41+
public void SetEntryUid_SetsValue_WhenNonEmpty()
42+
{
43+
var client = CreateClient();
44+
client.SetEntryUid("entry123");
45+
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
46+
}
47+
48+
[Fact]
49+
public void SetEntryUid_DoesNotSet_WhenEmpty()
50+
{
51+
var client = CreateClient();
52+
client.SetEntryUid("entry123");
53+
client.SetEntryUid("");
54+
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
55+
}
56+
57+
[Fact]
58+
public void SetEntryUid_DoesNotSet_WhenNull()
59+
{
60+
var client = CreateClient();
61+
client.SetEntryUid("entry123");
62+
client.SetEntryUid(null);
63+
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
64+
}
65+
66+
[Fact]
67+
public void ContentType_SetscurrentContenttypeUid_WhenNonEmpty()
68+
{
69+
var client = CreateClient();
70+
client.ContentType("blog");
71+
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
72+
}
73+
74+
[Fact]
75+
public void ContentType_DoesNotSet_WhenEmpty()
76+
{
77+
var client = CreateClient();
78+
client.ContentType("blog");
79+
client.ContentType("");
80+
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
81+
}
82+
83+
[Fact]
84+
public void ContentType_DoesNotSet_WhenNull()
85+
{
86+
var client = CreateClient();
87+
client.ContentType("blog");
88+
client.ContentType(null);
89+
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
90+
}
91+
92+
[Fact]
93+
public void ContentType_ReturnsContentTypeInstance()
94+
{
95+
var client = CreateClient();
96+
var contentType = client.ContentType("blog");
97+
Assert.NotNull(contentType);
98+
Assert.Equal("blog", contentType.ContentTypeId);
99+
}
100+
101+
[Fact]
102+
public void GlobalField_ReturnsGlobalFieldInstance()
103+
{
104+
var client = CreateClient();
105+
var globalField = client.GlobalField("author");
106+
Assert.NotNull(globalField);
107+
Assert.Equal("author", globalField.GlobalFieldId);
108+
}
109+
110+
[Fact]
111+
public void Asset_ReturnsAssetInstance()
112+
{
113+
var client = CreateClient();
114+
var asset = client.Asset("asset_uid");
115+
Assert.NotNull(asset);
116+
Assert.Equal("asset_uid", asset.Uid);
117+
}
118+
119+
[Fact]
120+
public void AssetLibrary_ReturnsAssetLibraryInstance()
121+
{
122+
var client = CreateClient();
123+
var assetLibrary = client.AssetLibrary();
124+
Assert.NotNull(assetLibrary);
125+
}
126+
127+
[Fact]
128+
public void Taxonomies_ReturnsTaxonomyInstance()
129+
{
130+
var client = CreateClient();
131+
var taxonomy = client.Taxonomies();
132+
Assert.NotNull(taxonomy);
133+
}
134+
135+
[Fact]
136+
public void GetVersion_ReturnsVersion()
137+
{
138+
var client = CreateClient();
139+
var t = client.GetVersion();
140+
Assert.Equal("1.2.3", client.GetVersion());
141+
}
142+
143+
[Fact]
144+
public void GetApplicationKey_ReturnsApiKey()
145+
{
146+
var client = CreateClient();
147+
Assert.Equal("api_key", client.GetApplicationKey());
148+
}
149+
150+
[Fact]
151+
public void GetAccessToken_ReturnsDeliveryToken()
152+
{
153+
var client = CreateClient();
154+
Assert.Equal("delivery_token", client.GetAccessToken());
155+
}
156+
157+
[Fact]
158+
public void GetLivePreviewConfig_ReturnsConfig()
159+
{
160+
var client = CreateClient();
161+
Assert.NotNull(client.GetLivePreviewConfig());
162+
}
163+
164+
[Fact]
165+
public void RemoveHeader_RemovesHeader()
166+
{
167+
var client = CreateClient();
168+
client.SetHeader("custom", "value");
169+
client.RemoveHeader("custom");
170+
var localHeaders = typeof(ContentstackClient)
171+
.GetField("_LocalHeaders", BindingFlags.NonPublic | BindingFlags.Instance)
172+
.GetValue(client) as Dictionary<string, object>;
173+
Assert.False(localHeaders.ContainsKey("custom"));
174+
}
175+
176+
[Fact]
177+
public void SetHeader_AddsHeader()
178+
{
179+
var client = CreateClient();
180+
client.SetHeader("custom", "value");
181+
var localHeaders = typeof(ContentstackClient)
182+
.GetField("_LocalHeaders", BindingFlags.NonPublic | BindingFlags.Instance)
183+
.GetValue(client) as Dictionary<string, object>;
184+
Assert.True(localHeaders.ContainsKey("custom"));
185+
Assert.Equal("value", localHeaders["custom"]);
186+
}
187+
188+
[Fact]
189+
public async Task LivePreviewQueryAsync_SetsLivePreviewConfigFields()
190+
{
191+
var client = CreateClient();
192+
client.ContentType("ctuid");
193+
client.ContentType("ctuid").Entry("euid");
194+
// Mock GetLivePreviewData to avoid actual HTTP call
195+
var method = typeof(ContentstackClient).GetMethod("GetLivePreviewData", BindingFlags.NonPublic | BindingFlags.Instance);
196+
method.Invoke(client, null); // Just to ensure method exists
197+
198+
var query = new Dictionary<string, string>
199+
{
200+
{ "live_preview", "hash" },
201+
{ "release_id", "rid" },
202+
{ "preview_timestamp", "ts" }
203+
};
204+
205+
// Patch GetLivePreviewData to return a dummy JObject
206+
207+
// Since GetLivePreviewData is private and does a real HTTP call,
208+
// we only test the config fields are set correctly before the call
209+
await client.LivePreviewQueryAsync(query);
210+
var v = client.GetLivePreviewConfig();
211+
Assert.Equal("ctuid", GetPrivateField(client, "currentContenttypeUid"));
212+
Assert.Equal("euid", GetPrivateField(client, "currentEntryUid"));
213+
Assert.Equal(true, v.Enable );
214+
Assert.Equal("rid", v.ReleaseId);
215+
Assert.Equal("ts", v.PreviewTimestamp);
216+
Assert.Equal("pt", v.PreviewToken);
217+
}
218+
219+
// For SyncRecursive, SyncPaginationToken, SyncToken, you should mock HTTP calls.
220+
// Here we just check that the methods exist and can be called (will throw if not configured).
221+
[Fact]
222+
public async Task SyncRecursive_ThrowsOrReturns()
223+
{
224+
var client = CreateClient();
225+
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncRecursive());
226+
}
227+
228+
[Fact]
229+
public async Task SyncPaginationToken_ThrowsOrReturns()
230+
{
231+
var client = CreateClient();
232+
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncPaginationToken("pagetoken"));
233+
}
234+
235+
[Fact]
236+
public async Task SyncToken_ThrowsOrReturns()
237+
{
238+
var client = CreateClient();
239+
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncToken("synctoken"));
240+
}
241+
}
242+
}

Contentstack.Core/Configuration/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal string getBaseUrl (LivePreviewConfig livePreviewConfig, string contentT
101101
{
102102
if (livePreviewConfig != null
103103
&& livePreviewConfig.Enable
104-
&& livePreviewConfig.LivePreview != "init"
104+
&& livePreviewConfig.LivePreview != "init" && !string.IsNullOrEmpty(livePreviewConfig.LivePreview)
105105
&& livePreviewConfig.ContentTypeUID == contentTypeUID)
106106
{
107107
return getLivePreviewUrl(livePreviewConfig);

Contentstack.Core/Contentstack.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3232
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
3333
<PackageReference Include="Markdig" Version="0.36.2" />
34-
<PackageReference Include="contentstack.utils" Version="1.0.5" />
34+
<PackageReference Include="contentstack.utils" Version="1.0.6" />
3535
</ItemGroup>
3636
<ItemGroup>
3737
<None Remove="Interfaces\" />

0 commit comments

Comments
 (0)