adrema/tests/Feature/Initialize/InitializeMembersTest.php

51 lines
1.8 KiB
PHP
Raw Normal View History

2023-02-07 02:45:15 +01:00
<?php
namespace Tests\Feature\Initialize;
use App\Initialize\InitializeMembers;
2023-02-07 23:42:49 +01:00
use App\Member\Member;
2023-02-14 13:57:21 +01:00
use App\Nami\Api\CoursesOfAction;
use App\Nami\Api\MembershipsOfAction;
2023-02-07 02:45:15 +01:00
use App\Setting\NamiSettings;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
2023-02-07 02:45:15 +01:00
use Tests\TestCase;
use Zoomyboy\LaravelNami\Data\MemberEntry;
2023-02-14 13:57:21 +01:00
use Zoomyboy\LaravelNami\Fakes\MemberFake;
2023-02-07 02:45:15 +01:00
use Zoomyboy\LaravelNami\Fakes\SearchFake;
class InitializeMembersTest extends TestCase
{
use DatabaseTransactions;
public function testItInitializesMembers(): void
{
$this->loginNami();
2023-02-07 23:42:49 +01:00
$member = Member::factory()->defaults()->create();
2023-02-07 02:45:15 +01:00
$api = app(NamiSettings::class)->login();
app(SearchFake::class)->fetches(1, 0, [
MemberEntry::factory()->toMember(['groupId' => 100, 'id' => 20]),
]);
2023-02-14 13:57:21 +01:00
app(MemberFake::class)->shows(100, 20);
MembershipsOfAction::shouldRun()->once()->withArgs(fn ($api, $id) => 20 === $id)->andReturn(collect([]));
CoursesOfAction::shouldRun()->once()->withArgs(fn ($api, $id) => 20 === $id)->andReturn(collect([]));
app(InitializeMembers::class)->handle($api);
}
public function testFetchesMembersViaCommandLine(): void
{
$this->loginNami();
$api = app(NamiSettings::class)->login();
app(SearchFake::class)->fetches(1, 0, [
MemberEntry::factory()->toMember(['groupId' => 100, 'id' => 20]),
]);
2023-02-14 13:57:21 +01:00
app(MemberFake::class)->shows(100, 20);
MembershipsOfAction::shouldRun()->once()->withArgs(fn ($api, $id) => 20 === $id)->andReturn(collect([]));
CoursesOfAction::shouldRun()->once()->withArgs(fn ($api, $id) => 20 === $id)->andReturn(collect([]));
Artisan::call('member:pull');
}
2023-02-07 02:45:15 +01:00
}