2023-02-07 02:45:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Initialize;
|
|
|
|
|
|
|
|
use App\Actions\PullCoursesAction;
|
|
|
|
use App\Actions\PullMemberAction;
|
|
|
|
use App\Actions\PullMembershipsAction;
|
|
|
|
use App\Initialize\InitializeMembers;
|
2023-02-07 23:42:49 +01:00
|
|
|
use App\Member\Member;
|
2023-02-07 02:45:15 +01:00
|
|
|
use App\Setting\NamiSettings;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2023-02-07 23:55:46 +01:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2023-02-07 02:45:15 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Data\MemberEntry;
|
2023-02-07 23:23:15 +01:00
|
|
|
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
|
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-07 23:42:49 +01:00
|
|
|
PullMemberAction::shouldRun()->once()->with(100, 20)->andReturn($member);
|
|
|
|
PullMembershipsAction::shouldRun()->once()->with($member);
|
|
|
|
PullCoursesAction::shouldRun()->once()->with($member);
|
2023-02-07 02:45:15 +01:00
|
|
|
|
|
|
|
app(InitializeMembers::class)->handle($api);
|
|
|
|
}
|
2023-02-07 23:23:15 +01:00
|
|
|
|
|
|
|
public function testFetchesMembersWhenJoinedAtDateIsNull(): void
|
|
|
|
{
|
|
|
|
$this->loginNami();
|
|
|
|
$api = app(NamiSettings::class)->login();
|
|
|
|
app(SearchFake::class)->fetches(1, 0, [
|
|
|
|
MemberEntry::factory()->toMember(['groupId' => 100, 'id' => 20]),
|
|
|
|
MemberEntry::factory()->toMember(['groupId' => 100, 'id' => 21]),
|
|
|
|
]);
|
|
|
|
PullMemberAction::shouldRun()->once()->with(100, 20)->andThrow(MemberDataCorruptedException::class, []);
|
|
|
|
PullMemberAction::shouldRun()->once()->with(100, 21);
|
|
|
|
PullMembershipsAction::shouldRun()->once();
|
|
|
|
PullCoursesAction::shouldRun()->once();
|
|
|
|
|
|
|
|
app(InitializeMembers::class)->handle($api);
|
|
|
|
}
|
2023-02-07 23:55:46 +01:00
|
|
|
|
|
|
|
public function testFetchesMembersViaCommandLine(): void
|
|
|
|
{
|
|
|
|
$this->loginNami();
|
|
|
|
$api = app(NamiSettings::class)->login();
|
|
|
|
|
|
|
|
app(SearchFake::class)->fetches(1, 0, [
|
|
|
|
MemberEntry::factory()->toMember(['groupId' => 100, 'id' => 20]),
|
|
|
|
]);
|
|
|
|
PullMemberAction::shouldRun()->once()->with(100, 20);
|
|
|
|
PullMembershipsAction::shouldRun()->once();
|
|
|
|
PullCoursesAction::shouldRun()->once();
|
|
|
|
|
|
|
|
Artisan::call('member:pull');
|
|
|
|
}
|
2023-02-07 02:45:15 +01:00
|
|
|
}
|