Skip to content

Fix duplicate Price Calculation Setup insert in Shopify pricing integration tests#9604

Closed
djukicmilica with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-unit-tests-integration-tests
Closed

Fix duplicate Price Calculation Setup insert in Shopify pricing integration tests#9604
djukicmilica with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-unit-tests-integration-tests

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Integration tests in codeunit 139605 (Shpfy Product Price Calc. Test) share persistent database state. UnitTestCalcPriceTestNewPricing inserts a Price Calculation Setup record with Code [1-1-10]-7002, and the subsequently-added UnitTestCalcPriceUsesCurrentWorkDate attempts to insert an identical record, causing a duplicate key error at runtime.

Changes

  • LibraryPriceCalculation.Codeunit.al — Added FindOrAddSetup: an idempotent variant of AddSetup that filters by Method/Type/Asset Type/Implementation and returns the existing record's Code if found, otherwise delegates to AddSetup.

    procedure FindOrAddSetup(var PriceCalculationSetup: Record "Price Calculation Setup";
        NewMethod: Enum "Price Calculation Method"; PriceType: Enum "Price Type";
        AssetType: Enum "Price Asset Type"; NewImplementation: Enum "Price Calculation Handler";
        NewDefault: Boolean): Code[100];
    begin
        PriceCalculationSetup.SetRange(Method, NewMethod);
        ...
        if not PriceCalculationSetup.FindFirst() then begin
            PriceCalculationSetup.Reset();
            exit(AddSetup(PriceCalculationSetup, NewMethod, PriceType, AssetType, NewImplementation, NewDefault));
        end;
        PriceCalculationSetup.Reset();
        exit(PriceCalculationSetup.Code);
    end;
  • ShpfyProductPriceCalcTest.Codeunit.al — Replaced AddSetup with FindOrAddSetup in both UnitTestCalcPriceTestNewPricing and UnitTestCalcPriceUsesCurrentWorkDate so neither method fails when the setup record already exists from a prior test in the same integration test run.

Copilot AI changed the title [WIP] Fix failing GitHub Actions job for unit tests Fix duplicate Price Calculation Setup insert in Shopify pricing integration tests Jul 20, 2026
Copilot AI requested a review from djukicmilica July 20, 2026 13:50
@github-actions github-actions Bot added the needs-approval Workflow runs require maintainer approval to start label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-approval Workflow runs require maintainer approval to start

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants