Skip to content

Commit

Permalink
Update test with clean tags
Browse files Browse the repository at this point in the history
  • Loading branch information
darjoo committed Oct 31, 2024
1 parent 8525f66 commit 4d118d0
Showing 1 changed file with 203 additions and 2 deletions.
205 changes: 203 additions & 2 deletions src/System Application/Test/Email/src/EmailTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1567,8 +1567,9 @@ codeunit 134685 "Email Test"
asserterror Email.MarkAsRead(EmailAccount."Account Id", EmailAccount.Connector, Any.AlphabeticText(10));
Assert.ExpectedError('The selected email connector does not support marking emails as read');
end;

#if not CLEAN26
[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure MarkEmailAsRead()
var
EmailAccount: Record "Email Account";
Expand All @@ -1586,6 +1587,7 @@ codeunit 134685 "Email Test"
end;

[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure MarkEmailAsReadFail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1605,6 +1607,45 @@ codeunit 134685 "Email Test"
asserterror Email.MarkAsRead(EmailAccount."Account Id", EmailAccount.Connector, Any.AlphabeticText(10));
Assert.ExpectedError('Failed to mark email as read');
end;
#endif

[Test]
procedure MarkEmailAsReadv3()
var
EmailAccount: Record "Email Account";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Marking email as read with a V3 connector should succeed with no errors
// [Given] An email account with a V3 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");

// [When] Mark email as read
// [Then] No error occurs
Email.MarkAsRead(EmailAccount."Account Id", EmailAccount.Connector, Any.AlphabeticText(10));
end;

[Test]
procedure MarkEmailAsReadFailv3()
var
EmailAccount: Record "Email Account";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Marking email as read with a V3 connector fails due to some error
// [Given] An email account with a V3 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");

// [Given] Force an error to occur when marking email as read
ConnectorMock.FailOnMarkAsRead(true);

// [When] Mark email as read
// [Then] An error occurs
asserterror Email.MarkAsRead(EmailAccount."Account Id", EmailAccount.Connector, Any.AlphabeticText(10));
Assert.ExpectedError('Failed to mark email as read');
end;

[Test]
procedure ReplyToEmailWithV1Connector()
Expand All @@ -1626,7 +1667,9 @@ codeunit 134685 "Email Test"
Assert.ExpectedError('The selected email connector does not support replying to emails');
end;

#if not CLEAN26
[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure ReplyToEmail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1646,6 +1689,7 @@ codeunit 134685 "Email Test"
end;

[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure ReplyToEmailWithNoRecipients()
var
EmailAccount: Record "Email Account";
Expand All @@ -1664,6 +1708,45 @@ codeunit 134685 "Email Test"
asserterror Email.Reply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector);
Assert.ExpectedError('You must specify a valid email account to send the message to');
end;
#endif
[Test]
procedure ReplyToEmailv3()
var
EmailAccount: Record "Email Account";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector should succeed with no errors
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReply(EmailMessage);

// [When] Reply to email
// [Then] No error occurs and reply returns true
Assert.IsTrue(Email.Reply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector), 'Did not succeed in replying the email');
end;

[Test]
procedure ReplyToEmailWithNoRecipientsv3()
var
EmailAccount: Record "Email Account";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector should succeed with no errors
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReply(EmailMessage, '');

// [When] Reply to email
// [Then] No error occurs and reply returns true
asserterror Email.Reply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector);
Assert.ExpectedError('You must specify a valid email account to send the message to');
end;

[Test]
procedure ReplyAllToEmailWithV1Connector()
Expand All @@ -1685,7 +1768,9 @@ codeunit 134685 "Email Test"
Assert.ExpectedError('The selected email connector does not support replying to emails');
end;

#if not CLEAN26
[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure ReplyAllToEmail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1705,6 +1790,7 @@ codeunit 134685 "Email Test"
end;

[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure ReplyAllToEmailFail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1725,6 +1811,48 @@ codeunit 134685 "Email Test"
// [Then] No error occurs and reply returns true
Assert.IsFalse(Email.ReplyAll(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector), 'Did succeed in replying the email when it should fail');
end;
#endif

[Test]
procedure ReplyAllToEmailv3()
var
EmailAccount: Record "Email Account";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector should succeed with no errors
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReplyAll(EmailMessage);

// [When] Reply to email
// [Then] No error occurs and reply returns true
Assert.IsTrue(Email.ReplyAll(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector), 'Did not succeed in replying the email');
end;

[Test]
procedure ReplyAllToEmailFailv3()
var
EmailAccount: Record "Email Account";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector fails due to some error
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReplyAll(EmailMessage);

// [Given] Force the connector to fail on reply
ConnectorMock.FailOnReply(true);

// [When] Reply to email
// [Then] No error occurs and reply returns true
Assert.IsFalse(Email.ReplyAll(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector), 'Did succeed in replying the email when it should fail');
end;

[Test]
procedure EnqueueReplyToEmailWithV1Connector()
Expand All @@ -1746,8 +1874,9 @@ codeunit 134685 "Email Test"
asserterror Email.EnqueueReply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);
Assert.ExpectedError('The selected email connector does not support replying to emails');
end;

#if not CLEAN26
[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure EnqueueReplyToEmail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1771,6 +1900,7 @@ codeunit 134685 "Email Test"
end;

[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure EnqueueReplyToEmailWithNoRecipients()
var
EmailAccount: Record "Email Account";
Expand All @@ -1790,6 +1920,51 @@ codeunit 134685 "Email Test"
asserterror Email.EnqueueReply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);
Assert.ExpectedError('You must specify a valid email account to send the message to');
end;
#endif

[Test]
procedure EnqueueReplyToEmailv3()
var
EmailAccount: Record "Email Account";
EmailOutbox: Record "Email Outbox";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector should succeed with no errors
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReply(EmailMessage);

// [When] Reply to email
// [Then] No error occurs and reply returns true
Assert.IsTrue(IsNullGuid(EmailOutbox."Message Id"), 'The email message id in the outbox should be empty');
Email.EnqueueReply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);

Assert.AreEqual(EmailMessage.GetId(), EmailOutbox."Message Id", 'The email message id should be the same as the one in the outbox');
end;

[Test]
procedure EnqueueReplyToEmailWithNoRecipientsv3()
var
EmailAccount: Record "Email Account";
EmailOutbox: Record "Email Outbox";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector should succeed with no errors
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReply(EmailMessage, '');

// [When] Reply to email
// [Then] No error occurs and reply returns true
asserterror Email.EnqueueReply(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);
Assert.ExpectedError('You must specify a valid email account to send the message to');
end;

[Test]
procedure EnqueueReplyAllToEmailWithV1Connector()
Expand All @@ -1812,7 +1987,9 @@ codeunit 134685 "Email Test"
Assert.ExpectedError('The selected email connector does not support replying to emails');
end;

#if not CLEAN26
[Test]
[Obsolete('v2 connector is replaced by v3 connector.', '26.0')]
procedure EnqueueReplyAllToEmailFail()
var
EmailAccount: Record "Email Account";
Expand All @@ -1834,6 +2011,30 @@ codeunit 134685 "Email Test"
// [Then] No error occurs and reply returns true
Email.EnqueueReplyAll(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);
end;
#endif

[Test]
procedure EnqueueReplyAllToEmailFail()

Check failure on line 2017 in src/System Application/Test/Email/src/EmailTest.Codeunit.al

View workflow job for this annotation

GitHub Actions / Build System Application Tests (No Isolation) (Default) / System Application Tests (No Isolation) (Default)

AL0440 The Codeunit 'Email Test' already defines a method called 'EnqueueReplyAllToEmailFail' with the same parameter types in 'System Application Test by Microsoft (26.0.2147483647.0)'.

Check failure on line 2017 in src/System Application/Test/Email/src/EmailTest.Codeunit.al

View workflow job for this annotation

GitHub Actions / Build System Application Modules (Default) / System Application Modules (Default)

AL0440 The Codeunit 'Email Test' already defines a method called 'EnqueueReplyAllToEmailFail' with the same parameter types in 'Email Test by Microsoft (26.0.2147483647.0)'.

Check failure on line 2017 in src/System Application/Test/Email/src/EmailTest.Codeunit.al

View workflow job for this annotation

GitHub Actions / Build System Application Tests (Default) / System Application Tests (Default)

AL0440 The Codeunit 'Email Test' already defines a method called 'EnqueueReplyAllToEmailFail' with the same parameter types in 'System Application Test by Microsoft (26.0.2147483647.0)'.
var
EmailAccount: Record "Email Account";
EmailOutbox: Record "Email Outbox";
EmailMessage: Codeunit "Email Message";
ConnectorMock: Codeunit "Connector Mock";
Any: Codeunit Any;
begin
// [Scenario] Replying to an email with a V2 connector fails due to some error
// [Given] An email account with a V2 connector
ConnectorMock.Initialize();
ConnectorMock.AddAccount(EmailAccount, Enum::"Email Connector"::"Test Email Connector v3");
CreateEmailReplyAll(EmailMessage);

// [Given] Force the connector to fail on reply
ConnectorMock.FailOnReply(true);

// [When] Reply to email
// [Then] No error occurs and reply returns true
Email.EnqueueReplyAll(EmailMessage, Any.AlphabeticText(10), EmailAccount."Account Id", EmailAccount.Connector, EmailOutbox);
end;

local procedure CreateEmail(var EmailMessage: Codeunit "Email Message")
var
Expand Down

0 comments on commit 4d118d0

Please sign in to comment.