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

[Email] Add GetAllV2Accounts API #1868

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ codeunit 8894 "Email Account"
end;

/// <summary>
/// Gets all of the email accounts registered in Business Central.
/// Gets all of the email accounts which implement the v2 interface registered in Business Central.
/// </summary>
/// <param name="LoadLogos">Flag, used to determine whether to load the logos for the accounts.</param>
/// <param name="TempEmailAccount">Out parameter holding the email accounts.</param>
procedure GetAllAccounts(var TempEmailAccount: Record "Email Account" temporary)
procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
begin
EmailAccountImpl.GetAllAccounts(false, TempEmailAccount);
EmailAccountImpl.GetAllV2Accounts(LoadLogos, TempEmailAccount);
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ codeunit 8889 "Email Account Impl."
CannotManageSetupErr: Label 'Your user account does not give you permission to set up email. Please contact your administrator.';

procedure GetAllAccounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
begin
GetAllAccounts(LoadLogos, false, TempEmailAccount);
end;

procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
begin
GetAllAccounts(LoadLogos, true, TempEmailAccount);
end;

local procedure GetAllAccounts(LoadLogos: Boolean; LoadV2Only: Boolean; var TempEmailAccount: Record "Email Account" temporary)
var
EmailAccounts: Record "Email Account";
Connector: Enum "Email Connector";
Expand All @@ -40,18 +50,19 @@ codeunit 8889 "Email Account Impl."
EmailAccounts.DeleteAll();
IEmailConnector.GetAccounts(EmailAccounts);

if EmailAccounts.FindSet() then
repeat
TempEmailAccount := EmailAccounts;
TempEmailAccount.Connector := Connector;
if (not LoadV2Only) or (LoadV2Only and IEmailConnector is "Email Connector v2") then
if EmailAccounts.FindSet() then
repeat
TempEmailAccount := EmailAccounts;
TempEmailAccount.Connector := Connector;

if LoadLogos then begin
ImportLogo(TempEmailAccount, Connector);
ImportLogoBlob(TempEmailAccount, Connector);
end;
if LoadLogos then begin
ImportLogo(TempEmailAccount, Connector);
ImportLogoBlob(TempEmailAccount, Connector);
end;

if not TempEmailAccount.Insert() then;
until EmailAccounts.Next() = 0;
if not TempEmailAccount.Insert() then;
until EmailAccounts.Next() = 0;
end;

// Sort by account name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,49 @@ codeunit 134686 "Email Accounts Test"
Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address');
end;

[Test]
procedure GetAllV2AccountsTest()
var
EmailAccountBuffer, EmailAccounts : Record "Email Account";
ConnectorMock: Codeunit "Connector Mock";
EmailAccount: Codeunit "Email Account";
begin
// [SCENARIO] GetAllV2Accounts retrieves all the registered accounts that implement the v2 interface

// [GIVEN] A connector is installed and no account is added
ConnectorMock.Initialize();

PermissionsMock.Set('Email Edit');

// [WHEN] GetAllAccounts is called
EmailAccount.GetAllV2Accounts(EmailAccounts);

// [THEN] The returned record is empty (there are no registered accounts)
Assert.IsTrue(EmailAccounts.IsEmpty(), 'Record should be empty');

// [GIVEN] An account is added to the connector
ConnectorMock.AddAccount(EmailAccountBuffer);
// [GIVEN] A v2 account is added to the connector
ConnectorMock.AddAccount(EmailAccountBuffer, Enum::"Email Connector"::"Test Email Connector v2");

// [WHEN] GetAllAccounts is called
EmailAccount.GetAllAccounts(EmailAccounts);

// [THEN] The returned record is not empty and the values are as expected
Assert.AreEqual(2, EmailAccounts.Count(), 'Record should not be empty');

// [WHEN] GetAllV2Accounts is called
EmailAccount.GetAllV2Accounts(EmailAccounts);

// [THEN] The returned record is not empty and the values are as expected
Assert.AreEqual(1, EmailAccounts.Count(), 'Record should not be empty');
EmailAccounts.FindFirst();
Assert.AreEqual(EmailAccountBuffer."Account Id", EmailAccounts."Account Id", 'Wrong account ID');
Assert.AreEqual(Enum::"Email Connector"::"Test Email Connector v2", EmailAccounts.Connector, 'Wrong connector');
Assert.AreEqual(EmailAccountBuffer.Name, EmailAccounts.Name, 'Wrong account name');
Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address');
end;

[Test]
procedure IsAnyAccountRegisteredTest()
var
Expand Down
Loading