Skip to content

Commit

Permalink
Added test to verify overwriting of mail sender
Browse files Browse the repository at this point in the history
  • Loading branch information
geisi committed Nov 27, 2023
1 parent 58de8a5 commit c879bcc
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion tests/MicrosoftGraphTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
'subject' => 'Dev Test',
'body' => [
'contentType' => 'HTML',
'content' => '<b>Test</b><img src="cid:' . $inlineImageContentId . '">'.PHP_EOL,
'content' => '<b>Test</b><img src="cid:'.$inlineImageContentId.'">'.PHP_EOL,
],
'toRecipients' => [
[
Expand Down Expand Up @@ -372,3 +372,92 @@
return true;
});
});

test('the configured mail sender can be overwritten', function () {
Config::set('mail.mailers.microsoft-graph', [
'transport' => 'microsoft-graph',
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.default', 'microsoft-graph');

Cache::set('microsoft-graph-api-access-token', 'foo_access_token', 3600);

Http::fake();

$mailable = new TestMail(false);
$mailable->from('[email protected]', 'Other Mail');

Mail::to('[email protected]')
->bcc('[email protected]')
->cc('[email protected]')
->send($mailable);

Http::assertSent(function (Request $value) {
expect($value)
->url()->toBe('https://graph.microsoft.com/v1.0/users/[email protected]/sendMail')
->hasHeader('Authorization', 'Bearer foo_access_token')->toBeTrue()
->body()->json()->toBe([
'message' => [
'subject' => 'Dev Test',
'body' => [
'contentType' => 'Text',
'content' => 'Test'.PHP_EOL,
],
'toRecipients' => [
[
'emailAddress' => [
'address' => '[email protected]',
],
],
],
'ccRecipients' => [
[
'emailAddress' => [
'address' => '[email protected]',
],
],
],
'bccRecipients' => [
[
'emailAddress' => [
'address' => '[email protected]',
],
],
],
'replyTo' => [],
'sender' => [
'emailAddress' => [
'address' => '[email protected]',
],
],
'attachments' => [
[
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => 'test-file-1.txt',
'contentType' => 'text',
'contentBytes' => 'Zm9vCg==',
'contentId' => 'test-file-1.txt',
'isInline' => false,
],
[
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => 'test-file-2.txt',
'contentType' => 'text',
'contentBytes' => 'Zm9vCg==',
'contentId' => 'test-file-2.txt',
'isInline' => false,
],
],
],
'saveToSentItems' => false,
]);

return true;
});
});

0 comments on commit c879bcc

Please sign in to comment.