Skip to content

Commit cb1f566

Browse files
OMpawar-21claude
andcommitted
test: add integration tests for taxonomy publish/unpublish/unlocalize and terms unlocalize (Test280-289)
Test280-283: Publish/Unpublish (sync + async) — looks up environment at runtime; marks Inconclusive if taxonomy_publish feature flag is not enabled on the test stack. Test284-285: Taxonomy.Unlocalize/UnlocalizeAsync — localizes first, then removes the locale. Test286-287: Term.Unlocalize/UnlocalizeAsync — same pattern on root term. Test288: Guard — Publish throws InvalidOperationException when UID is set. Test289: Guard — Unlocalize throws ArgumentException when no UID is set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7201b60 commit cb1f566

1 file changed

Lines changed: 243 additions & 0 deletions

File tree

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack017_TaxonomyTest.cs

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6492,6 +6492,249 @@ public void Test279_Should_Handle_Extreme_Boundary_Combinations()
64926492
}
64936493
}
64946494

6495+
[TestMethod]
6496+
public void Test280_Should_Publish_Taxonomy()
6497+
{
6498+
TestOutputLogger.LogContext("TestScenario", "Test280_Should_Publish_Taxonomy");
6499+
if (string.IsNullOrEmpty(_testLocaleCode))
6500+
{
6501+
AssertLogger.Inconclusive("No non-master locale available; skipping publish test.");
6502+
return;
6503+
}
6504+
6505+
// Look up an environment from the stack to use as a publish target.
6506+
ContentstackResponse envResp = _stack.Environments().Query().Find();
6507+
if (!envResp.IsSuccessStatusCode)
6508+
{
6509+
AssertLogger.Inconclusive("Could not fetch environments; skipping publish test.");
6510+
return;
6511+
}
6512+
var envJson = envResp.OpenJsonObjectResponse();
6513+
var envArray = envJson["environments"] as System.Text.Json.Nodes.JsonArray;
6514+
if (envArray == null || envArray.Count == 0)
6515+
{
6516+
AssertLogger.Inconclusive("No environments on stack; skipping publish test.");
6517+
return;
6518+
}
6519+
string envName = envArray[0]?["name"]?.ToString();
6520+
if (string.IsNullOrEmpty(envName))
6521+
{
6522+
AssertLogger.Inconclusive("Could not read environment name; skipping publish test.");
6523+
return;
6524+
}
6525+
6526+
var model = new TaxonomyPublishModel
6527+
{
6528+
Locales = new List<string> { _testLocaleCode },
6529+
Environments = new List<string> { envName },
6530+
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
6531+
};
6532+
ContentstackResponse response = _stack.Taxonomy().Publish(model);
6533+
// 403 = taxonomy_publish feature not enabled on this stack — treat as inconclusive.
6534+
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
6535+
{
6536+
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
6537+
return;
6538+
}
6539+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Publish failed: {response.OpenResponse()}", "PublishTaxonomySuccess");
6540+
}
6541+
6542+
[TestMethod]
6543+
public async Task Test281_Should_Publish_Taxonomy_Async()
6544+
{
6545+
TestOutputLogger.LogContext("TestScenario", "Test281_Should_Publish_Taxonomy_Async");
6546+
if (string.IsNullOrEmpty(_testLocaleCode))
6547+
{
6548+
AssertLogger.Inconclusive("No non-master locale available; skipping async publish test.");
6549+
return;
6550+
}
6551+
6552+
ContentstackResponse envResp = _stack.Environments().Query().Find();
6553+
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
6554+
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
6555+
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
6556+
string envName = envArray[0]?["name"]?.ToString();
6557+
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }
6558+
6559+
var model = new TaxonomyPublishModel
6560+
{
6561+
Locales = new List<string> { _testLocaleCode },
6562+
Environments = new List<string> { envName },
6563+
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
6564+
};
6565+
ContentstackResponse response = await _stack.Taxonomy().PublishAsync(model);
6566+
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
6567+
{
6568+
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
6569+
return;
6570+
}
6571+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"PublishAsync failed: {response.OpenResponse()}", "PublishTaxonomyAsyncSuccess");
6572+
}
6573+
6574+
[TestMethod]
6575+
public void Test282_Should_Unpublish_Taxonomy()
6576+
{
6577+
TestOutputLogger.LogContext("TestScenario", "Test282_Should_Unpublish_Taxonomy");
6578+
if (string.IsNullOrEmpty(_testLocaleCode))
6579+
{
6580+
AssertLogger.Inconclusive("No non-master locale available; skipping unpublish test.");
6581+
return;
6582+
}
6583+
6584+
ContentstackResponse envResp = _stack.Environments().Query().Find();
6585+
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
6586+
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
6587+
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
6588+
string envName = envArray[0]?["name"]?.ToString();
6589+
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }
6590+
6591+
var model = new TaxonomyPublishModel
6592+
{
6593+
Locales = new List<string> { _testLocaleCode },
6594+
Environments = new List<string> { envName },
6595+
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
6596+
};
6597+
ContentstackResponse response = _stack.Taxonomy().Unpublish(model);
6598+
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
6599+
{
6600+
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
6601+
return;
6602+
}
6603+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Unpublish failed: {response.OpenResponse()}", "UnpublishTaxonomySuccess");
6604+
}
6605+
6606+
[TestMethod]
6607+
public async Task Test283_Should_Unpublish_Taxonomy_Async()
6608+
{
6609+
TestOutputLogger.LogContext("TestScenario", "Test283_Should_Unpublish_Taxonomy_Async");
6610+
if (string.IsNullOrEmpty(_testLocaleCode))
6611+
{
6612+
AssertLogger.Inconclusive("No non-master locale available; skipping async unpublish test.");
6613+
return;
6614+
}
6615+
6616+
ContentstackResponse envResp = _stack.Environments().Query().Find();
6617+
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
6618+
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
6619+
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
6620+
string envName = envArray[0]?["name"]?.ToString();
6621+
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }
6622+
6623+
var model = new TaxonomyPublishModel
6624+
{
6625+
Locales = new List<string> { _testLocaleCode },
6626+
Environments = new List<string> { envName },
6627+
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
6628+
};
6629+
ContentstackResponse response = await _stack.Taxonomy().UnpublishAsync(model);
6630+
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
6631+
{
6632+
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
6633+
return;
6634+
}
6635+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"UnpublishAsync failed: {response.OpenResponse()}", "UnpublishTaxonomyAsyncSuccess");
6636+
}
6637+
6638+
[TestMethod]
6639+
public void Test284_Should_Unlocalize_Taxonomy()
6640+
{
6641+
TestOutputLogger.LogContext("TestScenario", "Test284_Should_Unlocalize_Taxonomy");
6642+
if (string.IsNullOrEmpty(_testLocaleCode))
6643+
{
6644+
AssertLogger.Inconclusive("No non-master locale available; skipping taxonomy unlocalize test.");
6645+
return;
6646+
}
6647+
6648+
// Ensure the taxonomy is localized first so unlocalize has something to remove.
6649+
var localizeModel = new TaxonomyModel { Name = "Taxonomy For Unlocalize" };
6650+
var localizeColl = new ParameterCollection();
6651+
localizeColl.Add("locale", _testLocaleCode);
6652+
_stack.Taxonomy(_taxonomyUid).Localize(localizeModel, localizeColl);
6653+
6654+
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Unlocalize(_testLocaleCode);
6655+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Unlocalize failed: {response.OpenResponse()}", "UnlocalizeTaxonomySuccess");
6656+
}
6657+
6658+
[TestMethod]
6659+
public async Task Test285_Should_Unlocalize_Taxonomy_Async()
6660+
{
6661+
TestOutputLogger.LogContext("TestScenario", "Test285_Should_Unlocalize_Taxonomy_Async");
6662+
if (string.IsNullOrEmpty(_asyncTestLocaleCode))
6663+
{
6664+
AssertLogger.Inconclusive("No second non-master locale available; skipping async unlocalize test.");
6665+
return;
6666+
}
6667+
6668+
var localizeModel = new TaxonomyModel { Name = "Taxonomy For Unlocalize Async" };
6669+
var localizeColl = new ParameterCollection();
6670+
localizeColl.Add("locale", _asyncTestLocaleCode);
6671+
await _stack.Taxonomy(_taxonomyUid).LocalizeAsync(localizeModel, localizeColl);
6672+
6673+
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).UnlocalizeAsync(_asyncTestLocaleCode);
6674+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"UnlocalizeAsync failed: {response.OpenResponse()}", "UnlocalizeTaxonomyAsyncSuccess");
6675+
}
6676+
6677+
[TestMethod]
6678+
public void Test286_Should_Unlocalize_Term()
6679+
{
6680+
TestOutputLogger.LogContext("TestScenario", "Test286_Should_Unlocalize_Term");
6681+
if (string.IsNullOrEmpty(_testLocaleCode) || string.IsNullOrEmpty(_rootTermUid))
6682+
{
6683+
AssertLogger.Inconclusive("No non-master locale or root term available; skipping term unlocalize test.");
6684+
return;
6685+
}
6686+
6687+
// Localize the term first so unlocalize has something to remove.
6688+
var localizeModel = new TermModel { Name = "Root Term For Unlocalize" };
6689+
var localizeColl = new ParameterCollection();
6690+
localizeColl.Add("locale", _testLocaleCode);
6691+
_stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Localize(localizeModel, localizeColl);
6692+
6693+
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Unlocalize(_testLocaleCode);
6694+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term Unlocalize failed: {response.OpenResponse()}", "UnlocalizeTermSuccess");
6695+
}
6696+
6697+
[TestMethod]
6698+
public async Task Test287_Should_Unlocalize_Term_Async()
6699+
{
6700+
TestOutputLogger.LogContext("TestScenario", "Test287_Should_Unlocalize_Term_Async");
6701+
if (string.IsNullOrEmpty(_asyncTestLocaleCode) || string.IsNullOrEmpty(_rootTermUid))
6702+
{
6703+
AssertLogger.Inconclusive("No second non-master locale or root term available; skipping async term unlocalize test.");
6704+
return;
6705+
}
6706+
6707+
var localizeModel = new TermModel { Name = "Root Term For Unlocalize Async" };
6708+
var localizeColl = new ParameterCollection();
6709+
localizeColl.Add("locale", _asyncTestLocaleCode);
6710+
await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).LocalizeAsync(localizeModel, localizeColl);
6711+
6712+
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).UnlocalizeAsync(_asyncTestLocaleCode);
6713+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term UnlocalizeAsync failed: {response.OpenResponse()}", "UnlocalizeTermAsyncSuccess");
6714+
}
6715+
6716+
[TestMethod]
6717+
public void Test288_Should_Throw_When_Publish_With_Uid_Set()
6718+
{
6719+
TestOutputLogger.LogContext("TestScenario", "Test288_Should_Throw_When_Publish_With_Uid_Set");
6720+
var model = new TaxonomyPublishModel
6721+
{
6722+
Locales = new List<string> { "en-us" },
6723+
Environments = new List<string> { "development" },
6724+
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
6725+
};
6726+
AssertLogger.ThrowsException<InvalidOperationException>(
6727+
() => _stack.Taxonomy(_taxonomyUid).Publish(model), "PublishWithUidSet");
6728+
}
6729+
6730+
[TestMethod]
6731+
public void Test289_Should_Throw_When_Unlocalize_Without_Uid()
6732+
{
6733+
TestOutputLogger.LogContext("TestScenario", "Test289_Should_Throw_When_Unlocalize_Without_Uid");
6734+
AssertLogger.ThrowsException<ArgumentException>(
6735+
() => _stack.Taxonomy().Unlocalize("en-us"), "UnlocalizeWithoutUid");
6736+
}
6737+
64956738
private static Stack GetStack()
64966739
{
64976740
StackResponse response = StackResponse.getStack(_client.serializer);

0 commit comments

Comments
 (0)