Skip to content
Draft

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ codeunit 30103 "Shpfy Communication Mgt."

var
Shop: Record "Shpfy Shop";
CommunicationEvents: Codeunit "Shpfy Communication Events";
GraphQLQueries: Codeunit "Shpfy GraphQL Queries";
NextExecutionTime: DateTime;
VersionTok: Label '2026-01', Locked = true;
OutgoingRequestsNotEnabledConfirmLbl: Label 'Importing data to your Shopify shop is not enabled, do you want to go to shop card to enable?';
OutgoingRequestsNotEnabledErr: Label 'Importing data to your Shopify shop is not enabled, navigate to shop card to enable.';
IsTestInProgress: Boolean;
CategoryTok: Label 'Shopify Integration', Locked = true;
QueryParamTooLongTxt: Label 'Query param length exceeded 50000.', Locked = true;
QueryParamTooLongErr: Label 'Request length exceeded Shopify API limit.';
Expand Down Expand Up @@ -232,22 +230,19 @@ codeunit 30103 "Shpfy Communication Mgt."
Sleep(Wait);
end;

if IsTestInProgress then
CommunicationEvents.OnClientSend(HttpRequestMessage, HttpResponseMessage)
else
if HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
Clear(RetryCounter);
while (not HttpResponseMessage.IsBlockedByEnvironment) and (EvaluateResponse(HttpResponseMessage)) and (RetryCounter < MaxRetries) do begin
RetryCounter += 1;
Sleep(1000);
LogShopifyRequest(Url, Method, Request, HttpResponseMessage, Response, RetryCounter);
Clear(HttpClient);
Clear(HttpRequestMessage);
Clear(HttpResponseMessage);
CreateHttpRequestMessage(Url, Method, Request, HttpRequestMessage);
HttpClient.Send(HttpRequestMessage, HttpResponseMessage);
end;
if HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
Clear(RetryCounter);
while (not HttpResponseMessage.IsBlockedByEnvironment) and (EvaluateResponse(HttpResponseMessage)) and (RetryCounter < MaxRetries) do begin
RetryCounter += 1;
Sleep(1000);
LogShopifyRequest(Url, Method, Request, HttpResponseMessage, Response, RetryCounter);
Clear(HttpClient);
Clear(HttpRequestMessage);
Clear(HttpResponseMessage);
CreateHttpRequestMessage(Url, Method, Request, HttpRequestMessage);
HttpClient.Send(HttpRequestMessage, HttpResponseMessage);
end;
end;
if GetContent(HttpResponseMessage, Response) then;
ResponseHeaders := HttpResponseMessage.Headers();
LogShopifyRequest(Url, Method, Request, HttpResponseMessage, Response, RetryCounter);
Expand All @@ -257,28 +252,19 @@ codeunit 30103 "Shpfy Communication Mgt."
[NonDebuggable]
internal procedure Post(var Client: HttpClient; Url: Text; Content: HttpContent; var Response: HttpResponseMessage)
begin
if IsTestInProgress then
CommunicationEvents.OnClientPost(Url, Content, Response)
else
Client.Post(Url, Content, Response);
Client.Post(Url, Content, Response);
end;

[NonDebuggable]
internal procedure Get(var Client: HttpClient; Url: Text; var Response: HttpResponseMessage)
begin
if IsTestInProgress then
CommunicationEvents.OnClientGet(Url, Response)
else
Client.Get(Url, Response);
Client.Get(Url, Response);
end;

[TryFunction]
local procedure GetContent(HttpResponseMsg: HttpResponseMessage; var Response: Text)
begin
if IsTestInProgress then
CommunicationEvents.OnGetContent(HttpResponseMsg, Response)
else
HttpResponseMsg.Content.ReadAs(Response);
HttpResponseMsg.Content.ReadAs(Response);
end;

/// <summary>
Expand Down Expand Up @@ -311,8 +297,7 @@ codeunit 30103 "Shpfy Communication Mgt."
/// <returns>Return value of type Text.</returns>
local procedure ApiVersion(): Text
begin
if not IsTestInProgress then
CheckApiVersion();
CheckApiVersion();
exit(VersionTok);
end;

Expand Down Expand Up @@ -351,18 +336,12 @@ codeunit 30103 "Shpfy Communication Mgt."
HttpContent: HttpContent;
ContentHttpHeaders: HttpHeaders;
HttpHeaders: HttpHeaders;
ClearAccessToken: Text;
AccessToken: SecretText;
begin
HttpRequestMsg.SetRequestUri(url);
HttpRequestMsg.GetHeaders(HttpHeaders);


if IsTestInProgress then begin
CommunicationEvents.OnGetAccessToken(ClearAccessToken);
AccessToken := ClearAccessToken;
end else
AccessToken := GetAccessToken(Shop);
AccessToken := GetAccessToken(Shop);

HttpHeaders.Add('X-Shopify-Access-Token', AccessToken);
HttpRequestMsg.Method := Method;
Expand Down Expand Up @@ -564,20 +543,6 @@ codeunit 30103 "Shpfy Communication Mgt."
FeatureTelemetry.LogUsage('0000JW7', 'Shopify', 'A shop is set', Dimensions);
end;

/// <summary>
/// SetTestInProgress.
/// </summary>
/// <param name="TestInProgress">Boolean.</param>
internal procedure SetTestInProgress(TestInProgress: Boolean)
begin
IsTestInProgress := TestInProgress;
end;

internal procedure GetTestInProgress(): Boolean
begin
exit(IsTestInProgress);
end;

internal procedure GetShopRecord() ShopifyShop: Record "Shpfy Shop";
begin
if not ShopifyShop.Get(Shop.Code) then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ codeunit 30195 "Shpfy Inventory API"
end;
until ShopInventory.Next() = 0;

ExecuteInventoryGraphQL(JGraphQL, IGraphQL.GetExpectedCost());
if InputSize > 0 then
ExecuteInventoryGraphQL(JGraphQL, IGraphQL.GetExpectedCost());
end;
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
Parameters: Dictionary of [Text, Text];
JResponse: JsonToken;
begin
if CommunicationMgt.GetTestInProgress() then
exit;

CommunicationMgt.SetShop(Shop);

if Shop."Allow Outgoing Requests" then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ codeunit 30160 "Shpfy Order Fulfillments"
JFulfillments: JsonArray;
JResponse: JsonToken;
begin
if CommunicationMgt.GetTestInProgress() then
exit;
CommunicationMgt.SetShop(Shop);
Parameters.Add('OrderId', Format(OrderId));
GraphQLType := "Shpfy GraphQL Type"::GetOrderFulfillment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ codeunit 30170 "Shpfy Order Risks"
Parameters: Dictionary of [text, Text];
GraphQLType: Enum "Shpfy GraphQL Type";
begin
if CommunicationMgt.GetTestInProgress() then
exit;
CommunicationMgt.SetShop(OrderHeader."Shop Code");
Parameters.Add('OrderId', Format(OrderHeader."Shopify Order Id"));
JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType::OrderRisks, Parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ codeunit 30165 "Shpfy Orders API"
JAttrib: JsonObject;
begin
CommunicationMgt.SetShop(ShopifyShop);
if CommunicationMgt.GetTestInProgress() then
exit;
Clear(OrderAttribute);
OrderAttribute."Order Id" := OrderHeader."Shopify Order Id";
OrderAttribute."Key" := CopyStr(KeyName, 1, MaxStrLen(OrderAttribute."Key"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ permissionset 30104 "Shpfy - Objects"
codeunit "Shpfy Can Not Have Stock" = X,
codeunit "Shpfy Catalog API" = X,
codeunit "Shpfy Checklist Item List" = X,
codeunit "Shpfy Communication Events" = X,
codeunit "Shpfy Communication Mgt." = X,
codeunit "Shpfy Comp. By Default Comp." = X,
codeunit "Shpfy Comp. By Email/Phone" = X,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,7 @@ codeunit 30176 "Shpfy Product API"
Headers: HttpHeaders;
Response: HttpResponseMessage;
InStream: InStream;
IsTestInProgress: Boolean;
begin
OnBeforeUploadImage(TenantMedia, Url, IsTestInProgress);
if IsTestInProgress then
exit;

Content.GetHeaders(Headers);
if Headers.Contains('Content-Type') then
Headers.Remove('Content-Type');
Expand Down Expand Up @@ -751,8 +746,4 @@ codeunit 30176 "Shpfy Product API"
exit(CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JMedia, 'id')));
end;

[InternalEvent(false, false)]
procedure OnBeforeUploadImage(var TenantMedia: Record "Tenant Media"; var ResourceUrl: Text; var IsTestInProgress: Boolean)
begin
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ codeunit 30191 "Shpfy Shipping Charges"
JShipmentLines: JsonArray;
JResponse: JsonToken;
begin
if CommunicationMgt.GetTestInProgress() then
exit;
CommunicationMgt.SetShop(OrderHeader."Shop Code");
Parameters.Add('OrderId', Format(OrderHeader."Shopify Order Id"));
GraphQLType := "Shpfy GraphQL Type"::GetShipmentLines;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "data": { "stagedUploadsCreate": { "stagedTargets": [ { "url": "test.com/test", "resourceUrl": "test2.com/test2", "parameters": [] } ] } }, "extensions": { "cost": { "requestedQueryCost": 11, "actualQueryCost": 11, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1989, "restoreRate": 100 } } } }
{ "data": { "stagedUploadsCreate": { "stagedTargets": [ { "url": "https://test.com/test", "resourceUrl": "https://test2.com/test2", "parameters": [] } ] } }, "extensions": { "cost": { "requestedQueryCost": 11, "actualQueryCost": 11, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1989, "restoreRate": 100 } } } }
34 changes: 0 additions & 34 deletions src/Apps/W1/Shopify/Test/Base/ShpfyInitializeTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ using System.TestLibraries.Utilities;
/// </summary>
codeunit 139561 "Shpfy Initialize Test"
{
EventSubscriberInstance = Manual;

var
DummyCustomer: Record Customer;
DummyItem: Record Item;
TempShop: Record "Shpfy Shop" temporary;
Any: Codeunit Any;
LibraryAssert: Codeunit "Library Assert";
CommunicationMgt: Codeunit "Shpfy Communication Mgt.";
LibraryERM: Codeunit "Library - ERM";
LibraryRandom: Codeunit "Library - Random";
ShopifyAccessToken: Text;
#pragma warning disable AA0240
DummyCustomerEmailLbl: Label 'dummy@customer.com';
#pragma warning restore AA0240
Expand All @@ -50,15 +46,13 @@ codeunit 139561 "Shpfy Initialize Test"
RefundGLAccount: Record "G/L Account";
Shop: Record "Shpfy Shop";
VATPostingSetup: Record "VAT Posting Setup";
ShpfyInitializeTest: Codeunit "Shpfy Initialize Test";
Code: Code[10];
CustomerTemplateCode: Code[20];
ItemTemplateCode: Code[20];
PostingGroupCode: Code[20];
GenPostingType: Enum "General Posting Type";
UrlTxt: Label 'https://%1.myshopify.com', Comment = '%1 = Shop name', Locked = true;
begin
BindSubscription(ShpfyInitializeTest);
if not TempShop.IsEmpty() then
if Shop.Get(TempShop.Code) then
exit(Shop);
Expand Down Expand Up @@ -94,15 +88,13 @@ codeunit 139561 "Shpfy Initialize Test"
if Shop.Insert() then;
Commit();
CommunicationMgt.SetShop(Shop);
CommunicationMgt.SetTestInProgress(true);
CreateDummyCustomer(CustomerTemplateCode);
CreateDummyItem(ItemTemplateCode);
if not TempShop.Get(Code) then begin
TempShop := Shop;
TempShop.Insert();
Commit();
end;
UnbindSubscription(ShpfyInitializeTest);
exit(Shop);
end;

Expand Down Expand Up @@ -346,32 +338,6 @@ codeunit 139561 "Shpfy Initialize Test"
end;


[EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnGetAccessToken', '', true, false)]
local procedure OnGetAccessToken(var AccessToken: Text)
begin
if ShopifyAccessToken = '' then
ShopifyAccessToken := Any.AlphanumericText(50);
AccessToken := ShopifyAccessToken;
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)]
local procedure OnClientSend(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage)
begin
TestRequestHeaderContainsAccessToken(HttpRequestMessage);
end;

local procedure TestRequestHeaderContainsAccessToken(HttpRequestMessage: HttpRequestMessage)
var
Headers: HttpHeaders;
ShopifyAccessTokenTxt: Label 'X-Shopify-Access-Token', Locked = true;
Values: array[1] of Text;
begin
HttpRequestMessage.GetHeaders(Headers);
LibraryAssert.IsTrue(Headers.Contains(ShopifyAccessTokenTxt), 'access token doesn''t exist');
Headers.GetValues(ShopifyAccessTokenTxt, Values);
LibraryAssert.IsTrue(Values[1] = ShopifyAccessToken, 'invalid access token');
end;

internal procedure CreateVATPostingSetup(BusinessPostingGroup: Code[20]; ProductPostingGroup: Code[20])
var
GeneralPostingSetup: Record "General Posting Setup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ codeunit 139563 "Shpfy Test Shopify"
// [SCENARIO] If a version is out of support then the API must be blocked.
// [WHEN] The Shop is created.
Shop := InitializeTest.CreateShop();
CommunicationMgt.SetTestInProgress(false);
SetupKeyVaultExpiryDate(CommunicationMgt.GetApiVersion());
EnvironmentInfoTestLibrary.SetTestabilitySoftwareAsAService(true);

Expand Down
Loading
Loading