fix: move local packages inside repo so remote server can install them
This commit is contained in:
1 parent
50e5f3e381
commit
30b2fb3958
40 files changed
+1671
-2
No files matched your search
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace PromoSeven\UltraMessage\Tests;
|
||||
|
||||
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||
use PromoSeven\UltraMessage\UltraMessageServiceProvider;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
protected function getPackageProviders($app): array
|
||||
{
|
||||
return [UltraMessageServiceProvider::class];
|
||||
}
|
||||
|
||||
protected function getEnvironmentSetUp($app): void
|
||||
{
|
||||
$app['config']->set('ultra-message.instance_id', 'instance123');
|
||||
$app['config']->set('ultra-message.token', 'test-token');
|
||||
$app['config']->set('ultra-message.enabled', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace PromoSeven\UltraMessage\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use PromoSeven\UltraMessage\UltraMessageChannel;
|
||||
use PromoSeven\UltraMessage\UltraMessageClient;
|
||||
use PromoSeven\UltraMessage\UltraMessageMessage;
|
||||
|
||||
class UltraMessageChannelTest extends TestCase
|
||||
{
|
||||
public function test_channel_calls_send_text_for_text_message(): void
|
||||
{
|
||||
Http::fake(['api.ultramsg.com/*' => Http::response(['sent' => 'true'], 200)]);
|
||||
|
||||
$client = new UltraMessageClient([
|
||||
'instance_id' => 'instance123',
|
||||
'token' => 'test-token',
|
||||
'timeout' => 30,
|
||||
'enabled' => true,
|
||||
]);
|
||||
$channel = new UltraMessageChannel($client);
|
||||
|
||||
$notifiable = new class {
|
||||
public string $whatsapp_number = '+971501234567';
|
||||
public function routeNotificationFor(string $channel, $notification = null): string
|
||||
{
|
||||
return $this->whatsapp_number;
|
||||
}
|
||||
};
|
||||
|
||||
$notification = new class extends Notification {
|
||||
public function toUltraMessage($notifiable): UltraMessageMessage
|
||||
{
|
||||
return UltraMessageMessage::text('Test message');
|
||||
}
|
||||
};
|
||||
|
||||
$channel->send($notifiable, $notification);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'messages/chat')
|
||||
&& $request['body'] === 'Test message'
|
||||
&& $request['to'] === '+971501234567';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_channel_uses_message_to_over_notifiable_route(): void
|
||||
{
|
||||
Http::fake(['api.ultramsg.com/*' => Http::response(['sent' => 'true'], 200)]);
|
||||
|
||||
$client = new UltraMessageClient([
|
||||
'instance_id' => 'instance123',
|
||||
'token' => 'test-token',
|
||||
'timeout' => 30,
|
||||
'enabled' => true,
|
||||
]);
|
||||
$channel = new UltraMessageChannel($client);
|
||||
|
||||
$notifiable = new class {
|
||||
public function routeNotificationFor(string $channel, $notification = null): string
|
||||
{
|
||||
return '+9710000000';
|
||||
}
|
||||
};
|
||||
|
||||
$notification = new class extends Notification {
|
||||
public function toUltraMessage($notifiable): UltraMessageMessage
|
||||
{
|
||||
return UltraMessageMessage::text('Override test')->to('+971999999');
|
||||
}
|
||||
};
|
||||
|
||||
$channel->send($notifiable, $notification);
|
||||
|
||||
Http::assertSent(fn($r) => $r['to'] === '+971999999');
|
||||
}
|
||||
|
||||
public function test_channel_skips_when_no_recipient(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
$client = new UltraMessageClient([
|
||||
'instance_id' => 'instance123',
|
||||
'token' => 'test-token',
|
||||
'timeout' => 30,
|
||||
'enabled' => true,
|
||||
]);
|
||||
$channel = new UltraMessageChannel($client);
|
||||
|
||||
$notifiable = new class {
|
||||
public function routeNotificationFor(string $channel, $notification = null): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
$notification = new class extends Notification {
|
||||
public function toUltraMessage($notifiable): UltraMessageMessage
|
||||
{
|
||||
return UltraMessageMessage::text('No recipient');
|
||||
}
|
||||
};
|
||||
|
||||
$channel->send($notifiable, $notification);
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace PromoSeven\UltraMessage\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use PromoSeven\UltraMessage\UltraMessageClient;
|
||||
use PromoSeven\UltraMessage\UltraMessageException;
|
||||
|
||||
class UltraMessageClientTest extends TestCase
|
||||
{
|
||||
private UltraMessageClient $client;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client = new UltraMessageClient([
|
||||
'instance_id' => 'instance123',
|
||||
'token' => 'test-token',
|
||||
'timeout' => 30,
|
||||
'enabled' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_send_text_posts_correct_payload(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response(['sent' => 'true', 'id' => 'msg1'], 200),
|
||||
]);
|
||||
|
||||
$result = $this->client->sendText('+971501234567', 'Hello World');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'instance123/messages/chat')
|
||||
&& $request['to'] === '+971501234567'
|
||||
&& $request['body'] === 'Hello World'
|
||||
&& $request['token'] === 'test-token';
|
||||
});
|
||||
|
||||
$this->assertEquals(['sent' => 'true', 'id' => 'msg1'], $result);
|
||||
}
|
||||
|
||||
public function test_send_text_throws_on_api_error(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response(['error' => 'invalid token'], 200),
|
||||
]);
|
||||
|
||||
$this->expectException(UltraMessageException::class);
|
||||
$this->expectExceptionMessage('invalid token');
|
||||
|
||||
$this->client->sendText('+971501234567', 'Hello');
|
||||
}
|
||||
|
||||
public function test_send_text_throws_on_http_failure(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response([], 500),
|
||||
]);
|
||||
|
||||
$this->expectException(UltraMessageException::class);
|
||||
|
||||
$this->client->sendText('+971501234567', 'Hello');
|
||||
}
|
||||
|
||||
public function test_send_returns_early_when_disabled(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
$client = new UltraMessageClient([
|
||||
'instance_id' => 'instance123',
|
||||
'token' => 'test-token',
|
||||
'timeout' => 30,
|
||||
'enabled' => false,
|
||||
]);
|
||||
|
||||
$result = $client->sendText('+971501234567', 'Hello');
|
||||
|
||||
Http::assertNothingSent();
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
public function test_send_image_posts_correct_payload(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response(['sent' => 'true'], 200),
|
||||
]);
|
||||
|
||||
$this->client->sendImage('+971501234567', 'https://example.com/img.jpg', 'Caption');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'instance123/messages/image')
|
||||
&& $request['image'] === 'https://example.com/img.jpg'
|
||||
&& $request['caption'] === 'Caption';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_send_document_posts_correct_payload(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response(['sent' => 'true'], 200),
|
||||
]);
|
||||
|
||||
$this->client->sendDocument('+971501234567', 'https://example.com/file.pdf', 'invoice.pdf', 'Your invoice');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'instance123/messages/document')
|
||||
&& $request['document'] === 'https://example.com/file.pdf'
|
||||
&& $request['filename'] === 'invoice.pdf'
|
||||
&& $request['caption'] === 'Your invoice';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_send_location_posts_correct_payload(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.ultramsg.com/*' => Http::response(['sent' => 'true'], 200),
|
||||
]);
|
||||
|
||||
$this->client->sendLocation('+971501234567', 25.197197, 55.2721877, 'Dubai, UAE');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'instance123/messages/location')
|
||||
&& $request['lat'] == 25.197197
|
||||
&& $request['lng'] == 55.2721877
|
||||
&& $request['address'] === 'Dubai, UAE';
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user