Skip to content

Commit e21fafe

Browse files
committed
Update TaxonomyLocalisationTest.cs
1 parent 371c5fe commit e21fafe

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Contentstack.Core.Tests/Integration/Taxonomy/TaxonomyLocalisationTest.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,87 @@ public async Task Term_Fetch_WithIncludeBranch_ReturnsBranchInfo()
446446
Assert.NotNull(result["uid"]?.ToString());
447447
}
448448

449+
[Fact(DisplayName = "TaxPublish - Term.Descendants with locale and fallback returns localized child+grandchild hierarchy")]
450+
public async Task Term_Descendants_WithLocaleAndFallback_ReturnsLocalizedHierarchy()
451+
{
452+
var client = CreateGadgetsClient();
453+
var (parentUid, childUid, grandchildUid) = await GetTermHierarchyAsync(client);
454+
455+
if (string.IsNullOrEmpty(parentUid))
456+
{
457+
Output.WriteLine("No parent/child/grandchild term chain found — skipping test.");
458+
return;
459+
}
460+
461+
LogArrange("Fetching localized descendants (depth=2) with fallback, down to grandchild level");
462+
LogContext("ParentTermUid", parentUid);
463+
LogContext("Locale", TestDataHelper.TaxPublishLocale);
464+
465+
LogAct("Calling Term(parentUid).SetLocale(locale).IncludeFallback().Depth(2).Descendants<JArray>()");
466+
var result = await client
467+
.Taxonomies(TestDataHelper.TaxPublishTaxonomyUid)
468+
.Term(parentUid)
469+
.SetLocale(TestDataHelper.TaxPublishLocale)
470+
.IncludeFallback()
471+
.Depth(2)
472+
.Descendants<Newtonsoft.Json.Linq.JArray>();
473+
474+
LogAssert("Verifying both child and grandchild are present, each localized or correctly fallen back");
475+
Assert.NotNull(result);
476+
var uids = result.Select(t => t["uid"]?.ToString()).ToList();
477+
Assert.Contains(childUid, uids);
478+
Assert.Contains(grandchildUid, uids);
479+
480+
// Every returned term must be either in the requested locale (translated) or the
481+
// master locale (fallen back) - never some third, unrelated locale.
482+
foreach (var term in result)
483+
{
484+
var locale = term["locale"]?.ToString();
485+
Assert.True(
486+
locale == TestDataHelper.TaxPublishLocale || locale == "en-us",
487+
$"Term '{term["uid"]}' returned unexpected locale '{locale}' - expected '{TestDataHelper.TaxPublishLocale}' (translated) or 'en-us' (fallback).");
488+
}
489+
}
490+
491+
[Fact(DisplayName = "TaxPublish - Term.Ancestors with locale and fallback returns localized ancestor chain")]
492+
public async Task Term_Ancestors_WithLocaleAndFallback_ReturnsLocalizedChain()
493+
{
494+
var client = CreateGadgetsClient();
495+
var (parentUid, childUid, grandchildUid) = await GetTermHierarchyAsync(client);
496+
497+
if (string.IsNullOrEmpty(grandchildUid))
498+
{
499+
Output.WriteLine("No parent/child/grandchild term chain found — skipping test.");
500+
return;
501+
}
502+
503+
LogArrange("Fetching localized ancestors for the grandchild term, with fallback");
504+
LogContext("GrandchildTermUid", grandchildUid);
505+
LogContext("Locale", TestDataHelper.TaxPublishLocale);
506+
507+
LogAct("Calling Term(grandchildUid).SetLocale(locale).IncludeFallback().Ancestors<JArray>()");
508+
var result = await client
509+
.Taxonomies(TestDataHelper.TaxPublishTaxonomyUid)
510+
.Term(grandchildUid)
511+
.SetLocale(TestDataHelper.TaxPublishLocale)
512+
.IncludeFallback()
513+
.Ancestors<Newtonsoft.Json.Linq.JArray>();
514+
515+
LogAssert("Verifying both parent and child (the ancestor chain) are present and correctly localized/fallen back");
516+
Assert.NotNull(result);
517+
var uids = result.Select(t => t["uid"]?.ToString()).ToList();
518+
Assert.Contains(childUid, uids);
519+
Assert.Contains(parentUid, uids);
520+
521+
foreach (var term in result)
522+
{
523+
var locale = term["locale"]?.ToString();
524+
Assert.True(
525+
locale == TestDataHelper.TaxPublishLocale || locale == "en-us",
526+
$"Term '{term["uid"]}' returned unexpected locale '{locale}' - expected '{TestDataHelper.TaxPublishLocale}' (translated) or 'en-us' (fallback).");
527+
}
528+
}
529+
449530
// ── 9. List all taxonomies ────────────────────────────────────────────
450531

451532
[Fact(DisplayName = "TaxPublish - List all taxonomies returns a collection")]

0 commit comments

Comments
 (0)