feat(DX-3233): Bulk publish/unpublish query params, api_version tests, and robust error handling#136
feat(DX-3233): Bulk publish/unpublish query params, api_version tests, and robust error handling#136OMpawar-21 wants to merge 8 commits intodevelopmentfrom
Conversation
…BulkUnpublishService.cs.
Description
In BulkUnpublishService.cs, two comment-only lines were added to document an alternative way of sending the bulk unpublish options:
skip_workflow_stage_check – A commented call AddQueryResource("skip_workflow_stage_check", "true") was added next to the existing Headers["skip_workflow_stage_check"] = "true" assignment.
approvals – A commented call AddQueryResource("approvals", "true") was added next to the existing Headers["approvals"] = "true" assignment.
…add integration tests - Bulk publish/unpublish: send skip_workflow_stage_check and approvals as query params via AddQueryResource instead of headers (BulkPublishService; BulkUnpublishService already used query params). - Unit tests: in BulkPublishServiceTest, BulkUnpublishServiceTest, and BulkOperationServicesTest, assert on QueryResources instead of Headers for these two flags. - Integration tests: add EnsureBulkTestContentTypeAndEntriesAsync() so bulk_test_content_type and at least one entry exist; add Test003a (bulk publish with skipWorkflowStage and approvals) and Test004a (bulk unpublish with same flags).
…ndling Integration tests (Contentstack015_BulkOperationTest): - API version 3.2: - Test003b: bulk publish with skipWorkflowStage, approvals, and apiVersion "3.2" (api_version header). - Test004b: bulk unpublish with skipWorkflowStage, approvals, and apiVersion "3.2" (api_version header). - Error handling and assertions: - Add FailWithError(operation, ex) to report HTTP status, ErrorCode, and API message on ContentstackErrorException. - In Test003a, Test004a, Test003b, Test004b: assert response.StatusCode == HttpStatusCode.OK and use FailWithError in catch. - Add Test004c: negative test for bulk unpublish with invalid data (empty entries, non-existent env); expect ContentstackErrorException and assert non-success status and presence of error message. - Usings: System.Net (HttpStatusCode), Contentstack.Management.Core.Exceptions (ContentstackErrorException).
…3a/004a/003b/004b), and 422/141 handling with console output. Ensure environment (find/create bulk_test_env) and workflow “oggy” (find/create with branches/stages) in ClassInitialize; add Test000c for environment; update Test000a/000b with find-or-create and Branches; Test002 creates five entries and assigns workflow stages; Test003a/004a/003b/004b use bulkTestEnvironmentUid, PublishWithReference, and skipWorkflowStage/approvals (003b/004b with api_version 3.2); treat 422 ErrorCode 141 as expected and log full message to console; fix UnPublish → Unpublish.
…ulk_UnPublish_With_SkipWorkflowStage_And_Approvals Added Proper Assertion and Status Code Mapping
| { | ||
| try | ||
| { | ||
| const string workflowName = "oggy"; |
| //[TestMethod] | ||
| //[DoNotParallelize] | ||
| //public async Task Test003_Should_Perform_Bulk_Publish_Operation() | ||
| //{ | ||
| // try | ||
| // { | ||
| // // Fetch existing entries from the content type | ||
| // List<EntryInfo> availableEntries = await FetchExistingEntries(); | ||
| // Assert.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation"); | ||
|
|
||
| // // Get available environments or use empty list if none available | ||
| // List<string> availableEnvironments = await GetAvailableEnvironments(); | ||
|
|
||
| // // Create bulk publish details | ||
| // var publishDetails = new BulkPublishDetails | ||
| // { | ||
| // Entries = availableEntries.Select(e => new BulkPublishEntry | ||
| // { | ||
| // Uid = e.Uid, | ||
| // ContentType = _contentTypeUid, | ||
| // Version = 1, | ||
| // Locale = "en-us" | ||
| // }).ToList(), | ||
| // Locales = new List<string> { "en-us" }, | ||
| // Environments = availableEnvironments | ||
| // }; |
| //public async Task Test004_Should_Perform_Bulk_Unpublish_Operation() | ||
| //{ | ||
| // try | ||
| // { | ||
| // // Fetch existing entries from the content type | ||
| // List<EntryInfo> availableEntries = await FetchExistingEntries(); | ||
| // Assert.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation"); | ||
|
|
||
| // // Get available environments | ||
| // List<string> availableEnvironments = await GetAvailableEnvironments(); | ||
|
|
||
| // // Create bulk unpublish details | ||
| // var unpublishDetails = new BulkPublishDetails | ||
| // { | ||
| // Entries = availableEntries.Select(e => new BulkPublishEntry | ||
| // { | ||
| // Uid = e.Uid, | ||
| // ContentType = _contentTypeUid, | ||
| // Version = 1, | ||
| // Locale = "en-us" | ||
| // }).ToList(), | ||
| // Locales = new List<string> { "en-us" }, | ||
| // Environments = availableEnvironments | ||
| // }; | ||
|
|
||
| // // Perform bulk unpublish | ||
| // ContentstackResponse response = _stack.BulkOperation().Unpublish(unpublishDetails); | ||
| // var responseJson = response.OpenJObjectResponse(); | ||
|
|
||
| // Assert.IsNotNull(response); |
There was a problem hiding this comment.
|
|
||
| <IsPackable>false</IsPackable> | ||
| <ReleaseVersion>$(Version)</ReleaseVersion> | ||
| <ReleaseVersion>0.1.3</ReleaseVersion> |
There was a problem hiding this comment.
Lets use the version itself rather than hard coding
| <Content Include="appsettings.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> |
| // Create a test environment for bulk operations | ||
| //await CreateTestEnvironment(); | ||
| //await CreateTestRelease(); |
There was a problem hiding this comment.
can we add this, since the test will be running in a new stack we can initialize here the workflow as well
|
|
||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test000a_Should_Create_Workflow_With_Two_Stages() |
There was a problem hiding this comment.
We should directly run the workflow and publish rule initialisation we can remove the findAll
Function CreateWorkFlow and CreatePublishRules should be created and called in initialisation here https://github.com/contentstack/contentstack-management-dotnet/pull/136/changes#r2894584568
|
|
||
| [TestMethod] | ||
| [DoNotParallelize] | ||
| public async Task Test000b_Should_Create_Publishing_Rule_For_Workflow_Stage2() |
There was a problem hiding this comment.
make it function and call it https://github.com/contentstack/contentstack-management-dotnet/pull/136/changes#r2894584568
| //public async Task Test000c_Should_Ensure_Environment_For_Workflow_Tests() | ||
| //{ | ||
| // try | ||
| // { | ||
| // if (string.IsNullOrEmpty(_bulkTestEnvironmentUid)) | ||
| // await EnsureBulkTestEnvironmentAsync(_stack); | ||
|
|
||
| // Assert.IsFalse(string.IsNullOrEmpty(_bulkTestEnvironmentUid), | ||
| // "Ensure environment failed: no existing environment and create failed. Create at least one environment in the stack or check permissions."); | ||
|
|
||
| // ContentstackResponse fetchResponse = _stack.Environment(_bulkTestEnvironmentUid).Fetch(); | ||
| // Assert.IsTrue(fetchResponse.IsSuccessStatusCode, | ||
| // $"Environment {_bulkTestEnvironmentUid} was set but fetch failed: HTTP {(int)fetchResponse.StatusCode}."); | ||
| // } | ||
| // catch (Exception ex) | ||
| // { | ||
| // FailWithError("Ensure environment for workflow tests", ex); | ||
| // } | ||
| //} |
There was a problem hiding this comment.
If this is not required remove it
| await CreateTestEnvironment(); | ||
| await CreateTestRelease(); | ||
| try { await CreateTestEnvironment(); } catch (ContentstackErrorException) { /* optional */ } | ||
| try { await CreateTestRelease(); } catch (ContentstackErrorException) { /* optional */ } |
There was a problem hiding this comment.
Add the action in catch block
Pull Request: Bulk publish/unpublish query params, api_version tests, and robust error handling
Summary
Add and align workflow, environment, and bulk publish/unpublish integration tests: ensure environment and workflow in ClassInitialize; create entries and assign workflow stages in Test002; run bulk publish (003a/003b) and unpublish (004a/004b) with skipWorkflowStage and approvals; treat 422 with ErrorCode 141 or 0 as expected and log full message to console so tests pass while still showing API error details.
Description
bulk_test_env) before workflow/publish-rule setup; store UID in_bulkTestEnvironmentUidand use it in all bulk publish/unpublish tests.["main"]and two stages ("New stage 1", "New stage 2") and matching payload (colors, SYS_ACL, etc.); reuse if already present.branches: ["main"]; reuse if already present.Versionfrom the create response, and assigns them to workflow stages (first half to stage 1, second half to stage 2)._bulkTestEnvironmentUid,publish_with_reference: true) andskip_workflow_stage_check/approvals; 003b/004b addapi_version: "3.2". When the API returns 422 with ErrorCode 141 (publish) or 141/0 (unpublish), the tests write the full failure message to the console and pass (assert status and error code); any other error still fails the test with a detailed message.Changes
Workflow and publish rule
Test000a – Create workflow with two stages
Branches = ["main"].#fe5cfb), "New stage 2" (color#3688bf).Test000b – Create publishing rule for workflow stage 2
Branches = ["main"].publishRuleModelfor the create payload; response stored in_bulkTestPublishRuleUid.EnsureBulkTestWorkflowAndPublishingRuleAsync (ClassInitialize)
_bulkTestEnvironmentUid.Environment
_bulkTestEnvironmentUid– shared environment UID for workflow and bulk tests.GetAvailableEnvironmentsAsync(stack); if any exist, set_bulkTestEnvironmentUidto the first."bulk_test_env"and set UID from response._bulkTestEnvironmentUidis set; optionally fetches the environment to verify.Entries and workflow stages
Test002 – Create five entries and assign to workflow stages
AssertWorkflowCreated()at start._createdEntries, create 5 entries, setVersionfrom each create response (_version).AssignEntriesToWorkflowStagesAsync(List<EntryInfo> entries)
BulkWorkflowUpdateBodyandCheckBulkJobStatus; swallows 412/366 (stage update not allowed).Bulk publish (003a, 003b)
Test003a – Bulk publish with skipWorkflowStage and approvals (no api_version)
_bulkTestEnvironmentUid; use it inEnvironments.Locales: ["en-us"],Environments: [_bulkTestEnvironmentUid],PublishWithReference: true,Versionfrom entry.Publish(publishDetails, skipWorkflowStage: true, approvals: true).Assert.Fail(failMessage).Test003b – Same as 003a with api_version "3.2"
Test003b_Should_Perform_Bulk_Publish_With_ApiVersion_3_2_With_SkipWorkflowStage_And_Approvals.Publish(..., skipWorkflowStage: true, approvals: true, apiVersion: "3.2").FailWithError.Bulk unpublish (004a, 004b)
Test004a – Bulk unpublish with skipWorkflowStage and approvals
Unpublish(publishDetails, skipWorkflowStage: false, approvals: true).Assert.Fail(failMessage).Test004a_Should_Perform_Bulk_UnPublish_With_SkipWorkflowStage_And_Approvals.Test004b – Same as 004a with api_version "3.2"
Test004b_Should_Perform_Bulk_UnPublish_With_ApiVersion_3_2_With_SkipWorkflowStage_And_Approvals.Unpublish(..., skipWorkflowStage: true, approvals: true, apiVersion: "3.2").FailWithError.Assertions and console output
Console.WriteLine(failMessage)so the detailed message appears in console; then assert and return so the test passes.Docs and comments
Files changed
Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.csTesting
_bulkTestEnvironmentUid, workflow UIDs, and publish rule UID.