Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barud - tests added to the FA Locations and Fixed Assets APIs #25012

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Apps/W1/APIV2/app/src/pages/APIV2FALocations.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
page 30097 "APIV2 - FA Locations"
{
DelayedInsert = true;
APIVersion = 'v2.0';
EntityCaption = 'Fixed Asset Location';
EntitySetCaption = 'Fixed Asset Locations';
PageType = API;
ODataKeyFields = SystemId;
EntityName = 'fixedAssetLocation';
EntitySetName = 'fixedAssetLocations';
SourceTable = "FA Location";
Extensible = false;

layout
{
area(Content)
{
repeater(Group)
{
field(id; Rec.SystemId)
{
Caption = 'Id';
Editable = false;
}
field(code; Rec.Code)
{
Caption = 'Code';
}
field(displayName; Rec.Name)
{
Caption = 'Name';
}
field(lastModifiedDateTime; Rec.SystemModifiedAt)
{
Caption = 'Last Modified Date';
}
}
}
}
}
69 changes: 69 additions & 0 deletions Apps/W1/APIV2/app/src/pages/APIV2FixedAssets.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
page 30098 "APIV2 - Fixed Assets"
{
APIVersion = 'v2.0';
EntityCaption = 'Fixed Asset';
EntitySetCaption = 'Fixed Assets';
ChangeTrackingAllowed = true;
DelayedInsert = true;
EntityName = 'fixedAsset';
EntitySetName = 'fixedAssets';
ODataKeyFields = SystemId;
PageType = API;
SourceTable = "Fixed Asset";
Extensible = false;

layout
{
area(content)
{
repeater(Group)
{
field(id; Rec.SystemId)
{
Caption = 'Id';
Editable = false;
}
field(number; Rec."No.")
{
Caption = 'No.';
}
field(displayName; Rec.Description)
{
Caption = 'Description';
}
field(faLocationCode; Rec."FA Location Code")
{
Caption = 'FA Location Code';
}
field(faClassCode; Rec."FA Class Code")
{
Caption = 'FA Class Code';
}
field(faSubclassCode; Rec."FA Subclass Code")
{
Caption = 'FA Subclass Code';
}
field(blocked; Rec.Blocked)
{
Caption = 'Blocked';
}
field(serialNo; Rec."Serial No.")
{
Caption = 'Serial No.';
}
field(responsibleEmployee; Rec."Responsible Employee")
{
Caption = 'Responsible Employee';
}
field(underMaintenance; Rec."Under Maintenance")
{
Caption = 'Under Maintenance';
}
field(lastModifiedDateTime; Rec.SystemModifiedAt)
{
Caption = 'Last Modified Date';
}
}
}
}
}
161 changes: 161 additions & 0 deletions Apps/W1/APIV2/test/src/APIV2FALocationsE2E.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
codeunit 139900 "APIV2 - FA Locations E2E"
{
// version Test,W1,All

Subtype = Test;
TestPermissions = Disabled;

trigger OnRun()
begin
// [FEATURE] [Api] [Location]
end;

var
Assert: Codeunit Assert;
LibraryGraphMgt: Codeunit "Library - Graph Mgt";
LibraryUtility: Codeunit "Library - Utility";
IsInitialized: Boolean;
EmptyJSONErr: Label 'JSON should not be empty.';
ServiceNameTxt: Label 'fixedAssetLocations';

local procedure Initialize()
begin
if IsInitialized then
exit;

IsInitialized := true;
Commit();
end;

[Test]
procedure TestGetFALocation()
var
FALocation: Record "FA Location";
Response: Text;
TargetURL: Text;
begin
// [SCENARIO] User can get a Fixed Asset Location with a GET request to the service.
Initialize();

// [GIVEN] A Fixed Asset Location exists in the system.
CreateFALocation(FALocation);

// [WHEN] The user makes a GET request for a given Fixed Asset Location.
TargetURL := LibraryGraphMgt.CreateTargetURL(FALocation.SystemId, Page::"APIV2 - FA Locations", ServiceNameTxt);
LibraryGraphMgt.GetFromWebService(Response, TargetURL);

// [THEN] The response text contains the Fixed Asset Location information.
VerifyProperties(Response, FALocation);
end;

[Test]
procedure TestCreateFALocation()
var
FALocation: Record "FA Location";
TempFALocation: Record "FA Location" temporary;
FALocationJSON: Text;
TargetURL: Text;
Response: Text;
begin
// [SCENARIO] User can create a new Fixed Asset Location through a POST method.
Initialize();

// [GIVEN] The user has constructed a Fixed Asset Location JSON object to send to the service.
CreateFALocation(TempFALocation);
FALocationJSON := GetFALocationJSON(TempFALocation);

// [WHEN] The user posts the JSON to the service.
TargetURL := LibraryGraphMgt.CreateTargetURL('', Page::"APIV2 - FA Locations", ServiceNameTxt);
LibraryGraphMgt.PostToWebService(TargetURL, FALocationJSON, Response);

// [THEN] The Fixed Asset Location has been created in the database with all the details.
FALocation.Get(TempFALocation.Code);
VerifyProperties(Response, FALocation);
end;

[Test]
procedure TestModifyFALocation()
var
FALocation: Record "FA Location";
TempFALocation: Record "FA Location" temporary;
RequestBody: Text;
Response: Text;
TargetURL: Text;
begin
// [SCENARIO] User can modify name in a Fixed Asset Location through a PATCH request.
Initialize();

// [GIVEN] A Fixed Asset Location exists with a name.
CreateFALocation(FALocation);
TempFALocation.TransferFields(FALocation);
FALocation.Code := LibraryUtility.GenerateRandomCodeWithLength(FALocation.FieldNo(Code), Database::"FA Location", 10);
TempFALocation.Name := LibraryUtility.GenerateGUID();
RequestBody := GetFALocationJSON(TempFALocation);

// [WHEN] The user makes a patch request to the service and specifies name field.
TargetURL := LibraryGraphMgt.CreateTargetURL(FALocation.SystemId, Page::"APIV2 - FA Locations", ServiceNameTxt);
LibraryGraphMgt.PatchToWebService(TargetURL, RequestBody, Response);

// [THEN] The response contains the new values.
VerifyProperties(Response, TempFALocation);

// [THEN] The Fixed Asset Location in the database contains the updated value.
FALocation.Get(FALocation.Code);
Assert.AreEqual(FALocation.Name, TempFALocation.Name, 'Names should be equal.');
end;

[Test]
procedure TestDeleteFALocation()
var
FALocation: Record "FA Location";
FALocationCode: Code[10];
TargetURL: Text;
Response: Text;
begin
// [SCENARIO] User can delete a Fixed Asset Location by making a DELETE request.
Initialize();

// [GIVEN] A Fixed Asset Location exists.
CreateFALocation(FALocation);
FALocationCode := FALocation.Code;

// [WHEN] The user makes a DELETE request to the endpoint for the Fixed Asset Location.
TargetURL := LibraryGraphMgt.CreateTargetURL(FALocation.SystemId, Page::"APIV2 - FA Locations", ServiceNameTxt);
LibraryGraphMgt.DeleteFromWebService(TargetURL, '', Response);

// [THEN] The response is empty.
Assert.AreEqual('', Response, 'DELETE response should be empty.');

// [THEN] The Fixed Asset Location is no longer in the database.
FALocation.SetRange(Code, FALocationCode);
Assert.IsTrue(FALocation.IsEmpty(), 'Fixed Asset Location should be deleted.');
end;

local procedure CreateFALocation(var FALocation: Record "FA Location")
begin
FALocation.Init();
FALocation.Code := LibraryUtility.GenerateRandomCodeWithLength(FALocation.FieldNo(Code), Database::"FA Location", 10);
FALocation.Name := LibraryUtility.GenerateGUID();
FALocation.Insert(true);
Commit();
end;

local procedure GetFALocationJSON(var FALocation: Record "FA Location") FALocationJSON: Text
begin
if FALocation.Code = '' then
FALocation.Code := LibraryUtility.GenerateRandomCodeWithLength(FALocation.FieldNo(Code), Database::"FA Location", 10);
if FALocation.Name = '' then
FALocation.Name := LibraryUtility.GenerateGUID();
FALocationJSON := LibraryGraphMgt.AddPropertytoJSON(FALocationJSON, 'code', FALocation.Code);
FALocationJSON := LibraryGraphMgt.AddPropertytoJSON(FALocationJSON, 'displayName', FALocation.Name);
exit(FALocationJSON);
end;

local procedure VerifyProperties(JSON: Text; FALocation: Record "FA Location")
begin
Assert.AreNotEqual('', JSON, EmptyJSONErr);
LibraryGraphMgt.VerifyIDInJSON(JSON);
LibraryGraphMgt.VerifyPropertyInJSON(JSON, 'code', FALocation.Code);
LibraryGraphMgt.VerifyPropertyInJSON(JSON, 'displayName', FALocation.Name);
end;
}
Loading
Loading