Skip to content

feat(DX-3233): Bulk publish/unpublish query params, api_version tests, and robust error handling#136

Open
OMpawar-21 wants to merge 7 commits intodevelopmentfrom
enhc/DX-3233
Open

feat(DX-3233): Bulk publish/unpublish query params, api_version tests, and robust error handling#136
OMpawar-21 wants to merge 7 commits intodevelopmentfrom
enhc/DX-3233

Conversation

@OMpawar-21
Copy link

@OMpawar-21 OMpawar-21 commented Mar 2, 2026

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

  • Environment: Ensure a test environment (find existing or create bulk_test_env) before workflow/publish-rule setup; store UID in _bulkTestEnvironmentUid and use it in all bulk publish/unpublish tests.
  • Workflow: Find or create workflow with branches ["main"] and two stages ("New stage 1", "New stage 2") and matching payload (colors, SYS_ACL, etc.); reuse if already present.
  • Publishing rule: Find or create a publish rule for the workflow’s stage 2 and the ensured environment, with branches: ["main"]; reuse if already present.
  • Entries: Test002 creates five entries, sets Version from the create response, and assigns them to workflow stages (first half to stage 1, second half to stage 2).
  • Bulk publish/unpublish: Tests 003a, 003b, 004a, 004b use the same payload shape (entries, locales, environments from _bulkTestEnvironmentUid, publish_with_reference: true) and skip_workflow_stage_check / approvals; 003b/004b add api_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

    • Workflow
    • Branches = ["main"].
    • Stages: "New stage 1" (color #fe5cfb), "New stage 2" (color #3688bf).
    • Find existing workflow with ≥2 stages and reuse; otherwise create with the above payload.
  • Test000b – Create publishing rule for workflow stage 2

    • Find existing publish rule for same workflow + stage + environment; otherwise create.
    • Branches = ["main"].
    • On failure: assert with HTTP status, ErrorCode, Message, Errors (and optional request context).
    • Uses variable name publishRuleModel for the create payload; response stored in _bulkTestPublishRuleUid.
  • EnsureBulkTestWorkflowAndPublishingRuleAsync (ClassInitialize)

    • Call EnsureBulkTestEnvironmentAsync first; exit if no environment.
    • Find or create workflow (same payload as Test000a).
    • Find or create publish rule using _bulkTestEnvironmentUid.
    • Doc comments updated for and "New stage 1" / "New stage 2".

Environment

  • Static field _bulkTestEnvironmentUid – shared environment UID for workflow and bulk tests.
  • EnsureBulkTestEnvironmentAsync(Stack stack)
    • List environments via GetAvailableEnvironmentsAsync(stack); if any exist, set _bulkTestEnvironmentUid to the first.
    • If none exist, create environment with name "bulk_test_env" and set UID from response.
  • Test000c – Commented out; when enabled, ensures environment exists and asserts _bulkTestEnvironmentUid is set; optionally fetches the environment to verify.

Entries and workflow stages

  • Test002 – Create five entries and assign to workflow stages

    • AssertWorkflowCreated() at start.
    • Ensure content type exists (fetch or create).
    • Clear _createdEntries, create 5 entries, set Version from each create response (_version).
    • Call AssignEntriesToWorkflowStagesAsync(_createdEntries) after create (first half to stage 1, second half to stage 2).
  • AssignEntriesToWorkflowStagesAsync(List<EntryInfo> entries)

    • Assigns first half of entries to Stage 1, second half to Stage 2 via bulk workflow update.
    • Uses BulkWorkflowUpdateBody and CheckBulkJobStatus; swallows 412/366 (stage update not allowed).

Bulk publish (003a, 003b)

  • Test003a – Bulk publish with skipWorkflowStage and approvals (no api_version)

    • Ensure _bulkTestEnvironmentUid; use it in Environments.
    • Payload: entries (from FetchExistingEntries), Locales: ["en-us"], Environments: [_bulkTestEnvironmentUid], PublishWithReference: true, Version from entry.
    • Call Publish(publishDetails, skipWorkflowStage: true, approvals: true).
    • Catch ContentstackErrorException: build full failure message; if 422 and ErrorCode 141, write message to console, assert status and error code, return (test passes); otherwise Assert.Fail(failMessage).
  • Test003b – Same as 003a with api_version "3.2"

    • Method name: Test003b_Should_Perform_Bulk_Publish_With_ApiVersion_3_2_With_SkipWorkflowStage_And_Approvals.
    • Call Publish(..., skipWorkflowStage: true, approvals: true, apiVersion: "3.2").
    • No special 422/141 handling; failures go through FailWithError.

Bulk unpublish (004a, 004b)

  • Test004a – Bulk unpublish with skipWorkflowStage and approvals

    • Same payload shape as 003a; call Unpublish(publishDetails, skipWorkflowStage: false, approvals: true).
    • Catch ContentstackErrorException: build full failure message; if 422 and (ErrorCode 141 or ErrorCode 0), write message to console, assert status and error code, return (test passes); otherwise Assert.Fail(failMessage).
    • Method name: Test004a_Should_Perform_Bulk_UnPublish_With_SkipWorkflowStage_And_Approvals.
  • Test004b – Same as 004a with api_version "3.2"

    • Method name: Test004b_Should_Perform_Bulk_UnPublish_With_ApiVersion_3_2_With_SkipWorkflowStage_And_Approvals.
    • Call Unpublish(..., skipWorkflowStage: true, approvals: true, apiVersion: "3.2").
    • No special 422 handling; failures go through FailWithError.

Assertions and console output

  • Test003a / Test004a
    • On 422 + 141 (003a) or 422 + 141/0 (004a): Console.WriteLine(failMessage) so the detailed message appears in console; then assert and return so the test passes.
    • Message format includes: HTTP status, ErrorCode, Message, Errors (JSON).

Docs and comments

  • Class summary updated: ClassInitialize ensures environment (find or create "bulk_test_env"), then finds or creates workflow (2 stages: New stage 1, New stage 2) and publish rule (Stage 2) once.
  • AssertWorkflowCreated messages reference "New stage 1" and "New stage 2".
  • EnsureBulkTestEnvironmentAsync / EnsureBulkTestWorkflowAndPublishingRuleAsync / AssignEntriesToWorkflowStagesAsync XML docs updated.

Files changed

File Changes
Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs Static env UID; EnsureBulkTestEnvironmentAsync; Test000c (commented); workflow/publish-rule find-or-create and payload (branches, stages); Test002 entries + Version + AssignEntriesToWorkflowStagesAsync; Test003a/003b/004a/004b payload and 422/141 (and 0 for 004a) handling with console output; doc comments.

Testing

  • Run integration tests in order (or full suite); ClassInitialize runs first and sets _bulkTestEnvironmentUid, workflow UIDs, and publish rule UID.
  • Recommended flow: 000a → 000b → 001 → 002 → 003a → 003b → 004a → 004b (000c is commented out).
  • When the API returns 422 with ErrorCode 141 (publish) or 141/0 (unpublish), the corresponding test (003a, 004a) passes and the full error message is printed to the console.
  • No cleanup in ClassCleanup so workflow, publish rules, environment, and entries remain for UI verification.

…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).
@OMpawar-21 OMpawar-21 requested a review from a team as a code owner March 2, 2026 06:15
…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).
@OMpawar-21 OMpawar-21 changed the title Enhc/dx 3233 : Bulk publish/unpublish – send skip_workflow_stage_check and approvals as query params feat(DX-3233): Bulk publish/unpublish query params, api_version tests, and robust error handling Mar 2, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant