Spaces:
Runtime error
Runtime error
File size: 2,773 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | <?php
declare(strict_types=1);
namespace OpenWA\Tests;
use OpenWA\Exceptions\OpenWANotFoundException;
use PHPUnit\Framework\TestCase;
class ProfileCallsTest extends TestCase
{
public function testProfileNameStatus(): void
{
$backend = new MockBackend();
$backend->on(200, ['success' => true, 'message' => 'Profile name updated']);
$backend->on(200, ['success' => true, 'message' => 'Profile status updated']);
$client = $backend->makeClient();
$client->profile->setProfileName('s', 'My Business');
$this->assertSame('PUT', $backend->calls()[0]['method']);
$this->assertSame('/api/sessions/s/profile/name', $backend->calls()[0]['path']);
$this->assertSame(['name' => 'My Business'], $backend->calls()[0]['body']);
$client->profile->setProfileStatus('s', '');
$this->assertSame('/api/sessions/s/profile/status', $backend->calls()[1]['path']);
$this->assertSame(['status' => ''], $backend->calls()[1]['body']);
}
public function testProfilePictureUrlAndBase64(): void
{
$backend = new MockBackend();
$backend->on(200, ['success' => true, 'message' => 'Profile picture updated']);
$backend->on(200, ['success' => true, 'message' => 'Profile picture updated']);
$client = $backend->makeClient();
$client->profile->setProfilePicture('s', ['url' => 'https://example.com/avatar.jpg']);
$this->assertSame('PUT', $backend->calls()[0]['method']);
$this->assertSame('/api/sessions/s/profile/picture', $backend->calls()[0]['path']);
$this->assertSame(['url' => 'https://example.com/avatar.jpg'], $backend->calls()[0]['body']);
$client->profile->setProfilePicture('s', ['base64' => 'aW1hZ2U=', 'mimetype' => 'image/jpeg']);
$this->assertSame(['base64' => 'aW1hZ2U=', 'mimetype' => 'image/jpeg'], $backend->calls()[1]['body']);
}
public function testRejectCall(): void
{
$backend = (new MockBackend())->on(200, ['success' => true]);
$client = $backend->makeClient();
$result = $client->calls->rejectCall('s', 'call-123');
$call = $backend->lastCall();
$this->assertSame('POST', $call['method']);
$this->assertSame('/api/sessions/s/calls/call-123/reject', $call['path']);
$this->assertTrue($result['success']);
}
public function testRejectCall404MapsToNotFoundException(): void
{
$backend = (new MockBackend())->on(404, [
'statusCode' => 404,
'message' => 'Call not found or no longer ringing',
'error' => 'Not Found',
]);
$this->expectException(OpenWANotFoundException::class);
$backend->makeClient()->calls->rejectCall('s', 'missing');
}
}
|