Skip to content

Commit

Permalink
feat(MicrosoftTeams): Add test for sending message
Browse files Browse the repository at this point in the history
- Created a new test file ClientTest.php in the MicrosoftTeams directory
- Added a test to verify the ability to send a message using the Microsoft Teams client
- Defined message content with various properties such as correlationId, originator, summary, themeColor, etc.
- Added sections and potential actions to the message for richer content and interactivity
- Mocked the response and asserted the ability to send the message successfully
  • Loading branch information
guanguans committed Feb 29, 2024
1 parent 28765fe commit 4a89348
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions tests/MicrosoftTeams/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/** @noinspection StaticClosureCanBeUsedInspection */
/** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

/**
* This file is part of the guanguans/notify.
*
* (c) guanguans <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Guanguans\NotifyTests\MicrosoftTeams;

use Guanguans\Notify\MicrosoftTeams\Authenticator;
use Guanguans\Notify\MicrosoftTeams\Client;
use Guanguans\Notify\MicrosoftTeams\Messages\Message;

use function Pest\Faker\faker;

it('can send message', function (): void {
$authenticator = new Authenticator('Your webhook url.');
$client = new Client($authenticator);
$message = Message::make([
'correlationId' => 'This is correlationId.',
'expectedActors' => [
'[email protected]',
],
'originator' => 'This is originator.',
'summary' => 'This is summary.',
'themeColor' => '0076D7',
'hideOriginalBody' => false,
'title' => 'This is title.',
'text' => 'This is text.',
'sections' => [],
'potentialAction' => [],
])
->addSection([
'title' => 'This is title.',
'startGroup' => true,
'activityImage' => 'This is activityImage.',
'activityTitle' => 'This is activityTitle.',
'activitySubtitle' => 'This is activitySubtitle.',
'activityText' => 'This is activityText.',
'heroImage' => 'This is heroImage.',
'text' => 'This is text.',
'facts' => [
[
'name' => 'This is name.',
'value' => 'This is value.',
],
],
'images' => [
'This is images.',
],
'potentialAction' => [],
])
->addPotentialAction([
'@type' => 'OpenUri',
'name' => 'This is name.',
'targets' => [
[
'os' => 'default',
'uri' => 'https://learn.microsoft.com/outlook/actionable-messages',
],
],
])
->addPotentialAction([
'@type' => 'HttpPOST',
'name' => 'This is name.',
'target' => 'https://learn.microsoft.com/outlook/actionable-messages',
'headers' => [
[
'name' => 'X-Version',
'value' => 'v1.0.0',
],
],
'body' => [
'field' => 'value',
],
'bodyContentType' => 'application/x-www-form-urlencoded',
])
->addPotentialAction([
'@type' => 'ActionCard',
'name' => 'This is name.',
'inputs' => [
[
'@type' => 'TextInput',
'id' => 'comment',
'isRequired' => true,
'title' => 'This is title.',
'value' => 'This is value.',
'isMultiline' => true,
],
],
'actions' => [],
])
->addPotentialAction([
'@type' => 'InvokeAddInCommand',
'name' => 'This is name.',
'addInId' => '527104a1-f1a5-475a-9199-7a968161c870',
'desktopCommandId' => 'show',
'initializationContext' => [
'property1' => 'This is property1.',
'property2' => 'This is property2.',
],
]);

expect($client)
->mock([
create_response(faker()->text()),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);

0 comments on commit 4a89348

Please sign in to comment.