44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Services\DingTalkService;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class DingTalkServiceTest extends TestCase
|
|
{
|
|
public function test_it_sends_text_to_a_robot_token(): void
|
|
{
|
|
Http::fake([
|
|
'https://oapi.dingtalk.com/robot/send?access_token=report-token' => Http::response([
|
|
'errcode' => 0,
|
|
]),
|
|
]);
|
|
|
|
$sent = (new DingTalkService)->sendTextToToken('report-token', '日报内容');
|
|
|
|
$this->assertTrue($sent);
|
|
Http::assertSent(fn ($request) => $request->url() === 'https://oapi.dingtalk.com/robot/send?access_token=report-token'
|
|
&& $request->data() === [
|
|
'msgtype' => 'text',
|
|
'text' => ['content' => '日报内容'],
|
|
'at' => ['atMobiles' => [], 'isAtAll' => false],
|
|
]);
|
|
}
|
|
|
|
public function test_it_reports_a_dingtalk_business_error(): void
|
|
{
|
|
Http::fake([
|
|
'https://oapi.dingtalk.com/robot/send?access_token=invalid-token' => Http::response([
|
|
'errcode' => 310000,
|
|
'errmsg' => 'invalid token',
|
|
]),
|
|
]);
|
|
|
|
$sent = (new DingTalkService)->sendTextToToken('invalid-token', '日报内容');
|
|
|
|
$this->assertFalse($sent);
|
|
}
|
|
}
|