adrema/tests/Feature/Initialize/InitializeMembersTest.php

52 lines
1.8 KiB
PHP
Raw Normal View History

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;
use Tests\TestCase;
use Zoomyboy\LaravelNami\Data\MemberEntry;
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);
}
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 02:45:15 +01:00
}