You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

<?php
namespace Tests\Unit;
use App\Models\CrawlSource;
use App\Services\Crawl\Adapters\AiSjtuResearchCenterAdapter;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class AiSjtuResearchCenterAdapterTest extends TestCase
{
public function test_fetches_research_team_members_from_api(): void
{
Http::fake([
'ai.sjtu.edu.cn/api/researchCenter*' => Http::response([
'researchCenters' => [
[
'id' => 3,
'name' => '数学基础研究中心',
'teams' => [
[
'id' => 0,
'name' => '范金燕',
'email' => 'jyfan@sjtu.edu.cn',
'phone' => '54740206',
'title' => '教授',
'direction' => '最优化理论与方法、多项式优化',
],
],
],
],
], 200),
]);
$adapter = new AiSjtuResearchCenterAdapter;
$source = new CrawlSource([
'adapter_code' => 'ai_sjtu_research_center_api',
'target_type' => 'teacher',
]);
$items = $adapter->fetch('https://ai.sjtu.edu.cn/center', $source, [
'max_results' => 10,
]);
$this->assertCount(1, $items);
$this->assertSame('范金燕', $items[0]->title);
$this->assertSame('jyfan@sjtu.edu.cn', $items[0]->extra['lead_author']['email']);
$this->assertSame('54740206', $items[0]->extra['phone']);
$this->assertSame(['最优化理论与方法', '多项式优化'], $items[0]->extra['research_direction_names']);
$this->assertSame('数学基础研究中心', $items[0]->extra['college_name']);
}
public function test_parse_research_direction_names(): void
{
$adapter = new AiSjtuResearchCenterAdapter;
$method = new \ReflectionMethod($adapter, 'parseResearchDirectionNames');
$method->setAccessible(true);
$this->assertSame(
['图像与信号处理', '数据科学', '最优化方法'],
$method->invoke($adapter, '图像与信号处理,数据科学,最优化方法'),
);
}
}