Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
feat: Added branch support in entry variants#207
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
edddd85df8af7b44aeae26c4ffbdb23f36a1a69925a75c31073cd66a7bdcf1c8444c8da5199698fb24d1f08194a2430f8c6d449683d192b74ae14d620c9c2eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3481,6 +3481,194 @@ await AssertLogger.ThrowsContentstackErrorAsync(async () => | ||
| } | ||
| #endregion | ||
| #region L — Branch Override Tests | ||
| private const string BranchOverrideUid = "dotnet_variant_br"; | ||
| private void TryDeleteBranch(string uid) | ||
| { | ||
| if (string.IsNullOrEmpty(uid)) return; | ||
| var force = new global::Contentstack.Management.Core.Queryable.ParameterCollection(); | ||
| force.Add("force", true); | ||
| try { _stack.Branch(uid).Delete(force); } catch { } | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public void Test083_Should_Create_Branch_For_Variant_Override_Tests() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_Setup"); | ||
| TryDeleteBranch(BranchOverrideUid); | ||
| try | ||
| { | ||
| var model = new BranchModel { Uid = BranchOverrideUid, Source = "main" }; | ||
| ContentstackResponse response = _stack.Branch().Create(model); | ||
| AssertLogger.IsNotNull(response.OpenJsonObjectResponse(), "response"); | ||
| } | ||
| catch (ContentstackErrorException cex) when ( | ||
| cex.StatusCode == HttpStatusCode.Conflict || | ||
| cex.StatusCode == (HttpStatusCode)422) | ||
| { | ||
| // Branch already exists from a previous run — that is fine for our purposes. | ||
| Console.WriteLine($"Branch '{BranchOverrideUid}' already exists (HTTP {(int)cex.StatusCode}); continuing."); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Assert.Inconclusive("Could not create a branch for branch-override tests (branching may not be enabled on this stack): " + ex.Message); | ||
| } | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public void Test084_Should_Fetch_Variant_On_Explicit_Branch() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_Fetch"); | ||
| try | ||
| { | ||
| // The variant/entry may not have been synced onto the new branch yet, so we only | ||
| // assert that the SDK successfully issues the request with the branch override — | ||
| // not that the API necessarily has matching content on that branch. | ||
| var response = _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant(_variantUid, BranchOverrideUid).Fetch(); | ||
| Console.WriteLine("Fetch on explicit branch response: " + response.OpenResponse()); | ||
| AssertLogger.IsTrue( | ||
| response.IsSuccessStatusCode, | ||
| "Expected a 2xx response when fetching a variant with a valid branch override (errors would have thrown ContentstackErrorException)", | ||
| "FetchVariantOnExplicitBranch"); | ||
| } | ||
| catch (ContentstackErrorException cex) | ||
| { | ||
| Console.WriteLine("Fetch on explicit branch failed (acceptable if content hasn't synced to the branch yet): " + cex.Message); | ||
| } | ||
OMpawar-21 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test085_Should_Fetch_Variant_On_Explicit_Branch_Async() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_FetchAsync"); | ||
| try | ||
| { | ||
| var response = await _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant(_variantUid, BranchOverrideUid).FetchAsync(); | ||
| Console.WriteLine("FetchAsync on explicit branch response: " + response.OpenResponse()); | ||
| AssertLogger.IsTrue( | ||
| response.IsSuccessStatusCode, | ||
| "Expected a 2xx response when fetching a variant with a valid branch override (errors would have thrown ContentstackErrorException)", | ||
| "FetchVariantOnExplicitBranchAsync"); | ||
OMpawar-21 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| catch (ContentstackErrorException cex) | ||
| { | ||
| Console.WriteLine("FetchAsync on explicit branch failed (acceptable if content hasn't synced to the branch yet): " + cex.Message); | ||
| } | ||
OMpawar-21 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test086_Should_Fail_To_Fetch_Variant_On_Invalid_Branch() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_InvalidBranch"); | ||
| await AssertLogger.ThrowsContentstackErrorAsync(async () => | ||
| { | ||
| var response = await _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant(_variantUid, "definitely_invalid_branch").FetchAsync(); | ||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| throw new ContentstackErrorException | ||
| { | ||
| StatusCode = response.StatusCode, | ||
| ErrorMessage = "Invalid branch UID" | ||
| }; | ||
| } | ||
| }, "FetchVariantOnInvalidBranch", HttpStatusCode.NotFound, (HttpStatusCode)422, HttpStatusCode.BadRequest, HttpStatusCode.Unauthorized, HttpStatusCode.Forbidden); | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test087_Should_Fallback_To_Stack_Branch_When_BranchUid_Is_Blank() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_BlankFallback"); | ||
| // A blank/whitespace branchUid must behave identically to omitting it entirely — | ||
| // i.e. fall back to the Stack's configured branch (main, in these tests). | ||
| var withoutOverride = await _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant().FindAsync(); | ||
| var withBlankOverride = await _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant(branchUid: " ").FindAsync(); | ||
| Assert.AreEqual(withoutOverride.IsSuccessStatusCode, withBlankOverride.IsSuccessStatusCode, | ||
| "A blank branchUid should fall back to the Stack's branch, matching the no-override request"); | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test088_Should_Publish_Variant_With_Explicit_Branch_Override() | ||
| { | ||
| if (string.IsNullOrEmpty(_entryUid) || string.IsNullOrEmpty(_variantUid)) | ||
| { | ||
| Assert.Inconclusive("Setup not completed. Ensure Test001 runs first."); | ||
| return; | ||
| } | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_Publish"); | ||
| var publishDetails = new PublishUnpublishDetails | ||
| { | ||
| Locales = new List<string> { "en-us" }, | ||
| Environments = new List<string> { "development" } | ||
| }; | ||
| try | ||
| { | ||
| var response = await _stack.ContentType(_contentTypeUid).Entry(_entryUid).Variant(_variantUid, BranchOverrideUid).PublishAsync(publishDetails, "en-us"); | ||
| Console.WriteLine("Publish with branch override response: " + response.OpenResponse()); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine("Publish with branch override failed (often due to missing 'development' environment on the branch). Continuing. Exception: " + ex.Message); | ||
| } | ||
Copilot marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public void Test089_Should_Cleanup_Branch_For_Variant_Override_Tests() | ||
| { | ||
| TestOutputLogger.LogContext("TestScenario", "VariantBranchOverride_Cleanup"); | ||
| TryDeleteBranch(BranchOverrideUid); | ||
| } | ||
| #endregion | ||
| } | ||
| /// <summary> | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.