From c46474b89ddea65d15f7090bb16e5625c10a0810 Mon Sep 17 00:00:00 2001 From: Prangshuman Das Date: Mon, 5 Oct 2026 15:24:09 +0200 Subject: [PATCH] [API tests] Separate APIV1 fixture and verification reliability fixes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session:3952f078-a881-4da8-ad96-13b727e48a91 --- .../src/APIV1AutomationRSPackage.Codeunit.al | 20 ++++--- .../test/src/APIV1GLEntriesE2E.Codeunit.al | 7 ++- .../src/APIV1PurchaseInvLinesE2E.Codeunit.al | 10 ++-- .../src/APIV1SalesCrMemoLinesE2E.Codeunit.al | 10 ++-- .../src/APIV1SalesInvLinesE2E.Codeunit.al | 10 ++-- .../src/APIV1SalesOrderLinesE2E.Codeunit.al | 10 ++-- .../src/APIV1SalesQuoteLinesE2E.Codeunit.al | 10 ++-- .../test/src/SalesInvoicesE2E.Codeunit.al | 1 + .../_Exclude_APIV1__Tests.DisabledTest.json | 53 +------------------ 9 files changed, 49 insertions(+), 82 deletions(-) diff --git a/src/Apps/W1/APIV1/test/src/APIV1AutomationRSPackage.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1AutomationRSPackage.Codeunit.al index b3cfb39fa44..fb446f7b2b2 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1AutomationRSPackage.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1AutomationRSPackage.Codeunit.al @@ -17,7 +17,6 @@ codeunit 139731 "APIV1 - Automation RS Package" LibraryGraphMgt: Codeunit "Library - Graph Mgt"; LibraryUtility: Codeunit "Library - Utility"; Assert: Codeunit "Assert"; - IsInitialized: Boolean; SamplePackageFile: Text; PackageCodeTxt: Label 'code', Locked = true; ActionImportTxt: Label 'Microsoft.NAV.import'; @@ -31,15 +30,11 @@ codeunit 139731 "APIV1 - Automation RS Package" TenantConfigPackageFile: Record "Tenant Config. Package File"; begin LibraryGraphMgt.SetLicenseSafeWorkDate(); - TenantConfigPackageFile.DELETEALL(TRUE); - - IF IsInitialized THEN - EXIT; - LibraryGraphMgt.SetAuthenticationProvider( Enum::"API Test Authentication"::"Microsoft Test Environment"); + TenantConfigPackageFile.DELETEALL(TRUE); + SamplePackageFile := GenerateSamplePackageFile(); - IsInitialized := TRUE; end; [Test] @@ -146,11 +141,12 @@ codeunit 139731 "APIV1 - Automation RS Package" StartTime := CURRENTDATETIME(); REPEAT + SelectLatestVersion(); ConfigPackage.FIND(); UNTIL (NOT IsImportPending(ConfigPackage)) OR (CURRENTDATETIME() - StartTime > 180000); - Assert.AreEqual(ConfigPackage."Import Status", ConfigPackage."Import Status"::Completed, 'Import Status should be completed.'); + Assert.AreEqual(ConfigPackage."Import Status"::Completed, ConfigPackage."Import Status", 'Import Status should be completed.'); // clean up after the test LibraryRapidStart.CleanUp(ConfigPackage.Code); @@ -194,11 +190,12 @@ codeunit 139731 "APIV1 - Automation RS Package" StartTime := CURRENTDATETIME(); REPEAT + SelectLatestVersion(); ConfigPackage.FIND(); UNTIL (NOT IsImportPending(ConfigPackage)) OR (CURRENTDATETIME() - StartTime > 180000); - Assert.AreEqual(ConfigPackage."Import Status", ConfigPackage."Import Status"::Error, 'Import Status should be error.'); + Assert.AreEqual(ConfigPackage."Import Status"::Error, ConfigPackage."Import Status", 'Import Status should be error.'); // clean up after the test LibraryRapidStart.CleanUp(ConfigPackage.Code); @@ -244,11 +241,12 @@ codeunit 139731 "APIV1 - Automation RS Package" StartTime := CURRENTDATETIME(); REPEAT + SelectLatestVersion(); ConfigPackage.FIND(); UNTIL (NOT IsApplyPending(ConfigPackage)) OR (CURRENTDATETIME() - StartTime > 180000); - Assert.AreEqual(ConfigPackage."Apply Status", ConfigPackage."Apply Status"::Completed, 'Apply Status should be completed.'); + Assert.AreEqual(ConfigPackage."Apply Status"::Completed, ConfigPackage."Apply Status", 'Apply Status should be completed.'); Assert.AreEqual(0, ConfigPackage."No. of Errors", 'There should be no errors.'); // clean up after the test @@ -332,7 +330,7 @@ codeunit 139731 "APIV1 - Automation RS Package" local procedure IsApplyPending(var ConfigPackage: Record "Config. Package"): Boolean begin - EXIT(ConfigPackage."Apply Status" IN [ConfigPackage."Import Status"::Scheduled, ConfigPackage."Apply Status"::InProgress]); + EXIT(ConfigPackage."Apply Status" IN [ConfigPackage."Apply Status"::Scheduled, ConfigPackage."Apply Status"::InProgress]); end; local procedure CreateTestPackage(var ConfigPackage: Record "Config. Package") diff --git a/src/Apps/W1/APIV1/test/src/APIV1GLEntriesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1GLEntriesE2E.Codeunit.al index db566bdf8bf..ad35c77aae9 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1GLEntriesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1GLEntriesE2E.Codeunit.al @@ -15,9 +15,9 @@ codeunit 139730 "APIV1 - GLEntries E2E" var Assert: Codeunit "Assert"; LibraryERM: Codeunit "Library - ERM"; - LibraryVariableStorage: Codeunit "Library - Variable Storage"; LibraryGraphMgt: Codeunit "Library - Graph Mgt"; IsInitialized: Boolean; + JournalTemplateName: Code[10]; ServiceNameTxt: Label 'generalLedgerEntries'; local procedure Initialize() @@ -94,7 +94,7 @@ codeunit 139730 "APIV1 - GLEntries E2E" CreateGeneralJournalBatch(GenJournalBatch); // Create General Journal Line. - LibraryVariableStorage.Enqueue(GenJournalBatch."Journal Template Name"); + JournalTemplateName := GenJournalBatch."Journal Template Name"; GeneralJournal.TRAP(); GeneralJournal.OPENEDIT(); GeneralJournal."Account Type".SETVALUE(GenJournalLine."Account Type"::"G/L Account"); @@ -124,7 +124,6 @@ codeunit 139730 "APIV1 - GLEntries E2E" local procedure UpdateAmountOnGenJournalLine(GenJournalBatch: Record "Gen. Journal Batch"; var GeneralJournal: TestPage "General Journal") begin - LibraryVariableStorage.Enqueue(GenJournalBatch."Journal Template Name"); LibraryERM.UpdateAmountOnGenJournalLine(GenJournalBatch, GeneralJournal); end; @@ -150,7 +149,7 @@ codeunit 139730 "APIV1 - GLEntries E2E" [ModalPageHandler] procedure GeneralJournalTemplateHandler(var GeneralJournalTemplateList: TestPage 250) begin - GeneralJournalTemplateList.FILTER.SETFILTER(Name, LibraryVariableStorage.DequeueText()); + GeneralJournalTemplateList.FILTER.SETFILTER(Name, JournalTemplateName); GeneralJournalTemplateList.OK().INVOKE(); end; } diff --git a/src/Apps/W1/APIV1/test/src/APIV1PurchaseInvLinesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1PurchaseInvLinesE2E.Codeunit.al index 0a4f6a11fce..7aca6bebe70 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1PurchaseInvLinesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1PurchaseInvLinesE2E.Codeunit.al @@ -716,6 +716,7 @@ codeunit 139738 "APIV1 - Purchase Inv Lines E2E" TargetURL: Text; ResponseText: Text; InvoiceLineJSON: Text; + LineDescription: Text; begin // [SCENARIO] Posting a line with description only will get a type item // [GIVEN] A post request with description only @@ -724,7 +725,8 @@ codeunit 139738 "APIV1 - Purchase Inv Lines E2E" COMMIT(); - InvoiceLineJSON := '{"description":"test"}'; + LineDescription := Format(CreateGuid()); + InvoiceLineJSON := LibraryGraphMgt.AddPropertytoJSON('', 'description', LineDescription); // [WHEN] we just POST a blank line TargetURL := LibraryGraphMgt @@ -736,8 +738,10 @@ codeunit 139738 "APIV1 - Purchase Inv Lines E2E" LibraryGraphMgt.PostToWebService(TargetURL, InvoiceLineJSON, ResponseText); // [THEN] Line of type Item is created - FindFirstPurchaseLine(PurchaseHeader, PurchaseLine); - PurchaseLine.FINDLAST(); + PurchaseLine.SETRANGE("Document Type", PurchaseHeader."Document Type"); + PurchaseLine.SETRANGE("Document No.", PurchaseHeader."No."); + PurchaseLine.SETRANGE(Description, LineDescription); + Assert.IsTrue(PurchaseLine.FINDFIRST(), 'Could not find the created purchase invoice line'); Assert.AreEqual('', PurchaseLine."No.", 'No should be blank'); Assert.AreEqual(PurchaseLine.Type, PurchaseLine.Type::Item, 'Wrong type is set'); diff --git a/src/Apps/W1/APIV1/test/src/APIV1SalesCrMemoLinesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1SalesCrMemoLinesE2E.Codeunit.al index 615c7c0e9bb..7a21ad24e18 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1SalesCrMemoLinesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1SalesCrMemoLinesE2E.Codeunit.al @@ -703,6 +703,7 @@ codeunit 139737 "APIV1 - Sales CrMemo Lines E2E" TargetURL: Text; ResponseText: Text; CreditMemoLineJSON: Text; + LineDescription: Text; begin // [SCENARIO] Posting a line with description only will get a type item // [GIVEN] A post request with description only @@ -711,7 +712,8 @@ codeunit 139737 "APIV1 - Sales CrMemo Lines E2E" COMMIT(); - CreditMemoLineJSON := '{"description":"test"}'; + LineDescription := Format(CreateGuid()); + CreditMemoLineJSON := LibraryGraphMgt.AddPropertytoJSON('', 'description', LineDescription); // [WHEN] we just POST a blank line TargetURL := LibraryGraphMgt @@ -723,8 +725,10 @@ codeunit 139737 "APIV1 - Sales CrMemo Lines E2E" LibraryGraphMgt.PostToWebService(TargetURL, CreditMemoLineJSON, ResponseText); // [THEN] Line of type Item is created - FindFirstSalesLine(SalesHeader, SalesLine); - SalesLine.FINDLAST(); + SalesLine.SETRANGE("Document Type", SalesHeader."Document Type"); + SalesLine.SETRANGE("Document No.", SalesHeader."No."); + SalesLine.SETRANGE(Description, LineDescription); + Assert.IsTrue(SalesLine.FINDFIRST(), 'Could not find the created credit memo line'); Assert.AreEqual('', SalesLine."No.", 'No should be blank'); Assert.AreEqual(SalesLine.Type, SalesLine.Type::Item, 'Wrong type is set'); diff --git a/src/Apps/W1/APIV1/test/src/APIV1SalesInvLinesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1SalesInvLinesE2E.Codeunit.al index 15bf9958bf0..3e03ed74ee9 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1SalesInvLinesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1SalesInvLinesE2E.Codeunit.al @@ -940,6 +940,7 @@ codeunit 139734 "APIV1 - Sales Inv. Lines E2E" TargetURL: Text; ResponseText: Text; InvoiceLineJSON: Text; + LineDescription: Text; begin // [SCENARIO] Posting a line with description only will get a type item // [GIVEN] A post request with description only @@ -948,7 +949,8 @@ codeunit 139734 "APIV1 - Sales Inv. Lines E2E" COMMIT(); - InvoiceLineJSON := '{"description":"test"}'; + LineDescription := Format(CreateGuid()); + InvoiceLineJSON := LibraryGraphMgt.AddPropertytoJSON('', 'description', LineDescription); // [WHEN] we just POST a blank line TargetURL := LibraryGraphMgt @@ -960,8 +962,10 @@ codeunit 139734 "APIV1 - Sales Inv. Lines E2E" LibraryGraphMgt.PostToWebService(TargetURL, InvoiceLineJSON, ResponseText); // [THEN] Line of type Item is created - FindFirstSalesLine(SalesHeader, SalesLine); - SalesLine.FINDLAST(); + SalesLine.SETRANGE("Document Type", SalesHeader."Document Type"); + SalesLine.SETRANGE("Document No.", SalesHeader."No."); + SalesLine.SETRANGE(Description, LineDescription); + Assert.IsTrue(SalesLine.FINDFIRST(), 'Could not find the created invoice line'); Assert.AreEqual('', SalesLine."No.", 'No should be blank'); Assert.AreEqual(SalesLine.Type, SalesLine.Type::Item, 'Wrong type is set'); VerifyIdsAreBlank(ResponseText); diff --git a/src/Apps/W1/APIV1/test/src/APIV1SalesOrderLinesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1SalesOrderLinesE2E.Codeunit.al index cf5de4412b0..35cc1d6038d 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1SalesOrderLinesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1SalesOrderLinesE2E.Codeunit.al @@ -717,6 +717,7 @@ codeunit 139735 "APIV1 - Sales Order Lines E2E" TargetURL: Text; ResponseText: Text; OrderLineJSON: Text; + LineDescription: Text; begin // [SCENARIO] Posting a line with description only will get a type item // [GIVEN] A post request with description only @@ -725,7 +726,8 @@ codeunit 139735 "APIV1 - Sales Order Lines E2E" COMMIT(); - OrderLineJSON := '{"description":"test"}'; + LineDescription := Format(CreateGuid()); + OrderLineJSON := LibraryGraphMgt.AddPropertytoJSON('', 'description', LineDescription); // [WHEN] we just POST a blank line TargetURL := LibraryGraphMgt @@ -737,8 +739,10 @@ codeunit 139735 "APIV1 - Sales Order Lines E2E" LibraryGraphMgt.PostToWebService(TargetURL, OrderLineJSON, ResponseText); // [THEN] Line of type Item is created - FindFirstSalesLine(SalesHeader, SalesLine); - SalesLine.FINDLAST(); + SalesLine.SETRANGE("Document Type", SalesHeader."Document Type"); + SalesLine.SETRANGE("Document No.", SalesHeader."No."); + SalesLine.SETRANGE(Description, LineDescription); + Assert.IsTrue(SalesLine.FINDFIRST(), 'Could not find the created order line'); Assert.AreEqual('', SalesLine."No.", 'No should be blank'); Assert.AreEqual(SalesLine.Type, SalesLine.Type::Item, 'Wrong type is set'); diff --git a/src/Apps/W1/APIV1/test/src/APIV1SalesQuoteLinesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/APIV1SalesQuoteLinesE2E.Codeunit.al index d1d53b26e59..c2f13ec003e 100644 --- a/src/Apps/W1/APIV1/test/src/APIV1SalesQuoteLinesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/APIV1SalesQuoteLinesE2E.Codeunit.al @@ -619,6 +619,7 @@ codeunit 139736 "APIV1 - Sales Quote Lines E2E" TargetURL: Text; ResponseText: Text; QuoteLineJSON: Text; + LineDescription: Text; begin // [SCENARIO] Posting a line with description only will get a type item // [GIVEN] A post request with description only @@ -627,7 +628,8 @@ codeunit 139736 "APIV1 - Sales Quote Lines E2E" COMMIT(); - QuoteLineJSON := '{"description":"test"}'; + LineDescription := Format(CreateGuid()); + QuoteLineJSON := LibraryGraphMgt.AddPropertytoJSON('', 'description', LineDescription); // [WHEN] we just POST a blank line TargetURL := LibraryGraphMgt @@ -639,8 +641,10 @@ codeunit 139736 "APIV1 - Sales Quote Lines E2E" LibraryGraphMgt.PostToWebService(TargetURL, QuoteLineJSON, ResponseText); // [THEN] Line of type Item is created - FindFirstSalesLine(SalesHeader, SalesLine); - SalesLine.FINDLAST(); + SalesLine.SETRANGE("Document Type", SalesHeader."Document Type"); + SalesLine.SETRANGE("Document No.", SalesHeader."No."); + SalesLine.SETRANGE(Description, LineDescription); + Assert.IsTrue(SalesLine.FINDFIRST(), 'Could not find the created quote line'); Assert.AreEqual('', SalesLine."No.", 'No should be blank'); Assert.AreEqual(SalesLine.Type, SalesLine.Type::Item, 'Wrong type is set'); diff --git a/src/Apps/W1/APIV1/test/src/SalesInvoicesE2E.Codeunit.al b/src/Apps/W1/APIV1/test/src/SalesInvoicesE2E.Codeunit.al index 6331acdecff..828e6482943 100644 --- a/src/Apps/W1/APIV1/test/src/SalesInvoicesE2E.Codeunit.al +++ b/src/Apps/W1/APIV1/test/src/SalesInvoicesE2E.Codeunit.al @@ -632,6 +632,7 @@ codeunit 139709 "Sales Invoices E2E" Initialize(); // [GIVEN] 2 invoices, one posted and one unposted without totals assigned + LibraryApplicationArea.EnableFoundationSetup(); LibraryGraphDocumentTools.CreateDocumentWithDiscountPctPending( SalesHeader, DiscountPct, SalesHeader."Document Type"::Invoice); SalesHeader.CALCFIELDS("Recalculate Invoice Disc."); diff --git a/src/DisabledTests/_Exclude_APIV1__Tests/_Exclude_APIV1__Tests.DisabledTest.json b/src/DisabledTests/_Exclude_APIV1__Tests/_Exclude_APIV1__Tests.DisabledTest.json index 35fefab11a3..fe51488c706 100644 --- a/src/DisabledTests/_Exclude_APIV1__Tests/_Exclude_APIV1__Tests.DisabledTest.json +++ b/src/DisabledTests/_Exclude_APIV1__Tests/_Exclude_APIV1__Tests.DisabledTest.json @@ -1,52 +1 @@ -[ - { - "codeunitId": 139734, - "codeunitName": "APIV1 - Sales Inv. Lines E2E", - "method": "TestPostingBlankLineDefaultsToItemType" - }, - { - "codeunitId": 139735, - "codeunitName": "APIV1 - Sales Order Lines E2E", - "method": "TestPostingBlankLineDefaultsToItemType" - }, - { - "codeunitId": 139736, - "codeunitName": "APIV1 - Sales Quote Lines E2E", - "method": "TestPostingBlankLineDefaultsToItemType" - }, - { - "codeunitId": 139737, - "codeunitName": "APIV1 - Sales CrMemo Lines E2E", - "method": "TestPostingBlankLineDefaultsToItemType" - }, - { - "codeunitId": 139738, - "codeunitName": "APIV1 - Purchase Inv Lines E2E", - "method": "TestPostingBlankLineDefaultsToItemType" - }, - { - "codeunitId": 139731, - "codeunitName": "APIV1 - Automation RS Package", - "method": "TestImportRSPackage" - }, - { - "codeunitId": 139731, - "codeunitName": "APIV1 - Automation RS Package", - "method": "TestImportWrongRSPackage" - }, - { - "codeunitId": 139731, - "codeunitName": "APIV1 - Automation RS Package", - "method": "TestApplyRSPackage" - }, - { - "codeunitId": 139730, - "codeunitName": "APIV1 - GLEntries E2E", - "method": "TestGetGLEntries" - }, - { - "codeunitId": 139709, - "codeunitName": "Sales Invoices E2E", - "method": "TestGetInvoicesAppliesDiscountPct" - } -] +[]