Add test for group instance
This commit is contained in:
parent
99974ec425
commit
db2671c11a
|
@ -2,48 +2,46 @@
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Zoomyboy\LaravelNami\Authentication\Auth;
|
use Zoomyboy\LaravelNami\Authentication\Auth;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
||||||
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
|
||||||
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
||||||
use Zoomyboy\LaravelNami\LoginException;
|
use Zoomyboy\LaravelNami\Group;
|
||||||
use Zoomyboy\LaravelNami\Nami;
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
use Zoomyboy\LaravelNami\NamiException;
|
use Zoomyboy\LaravelNami\NamiException;
|
||||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||||
|
|
||||||
class GroupsTest extends TestCase
|
class GroupsTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Auth::fake();
|
Auth::fake();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_groups(): void
|
public function testGetGroups(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success(12345, 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup']
|
1234 => ['name' => 'testgroup'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$group = Nami::login(12345, 'secret')->group(1234);
|
$group = Nami::login(12345, 'secret')->group(1234);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Group::class, $group);
|
||||||
$this->assertEquals('testgroup', $group->name);
|
$this->assertEquals('testgroup', $group->name);
|
||||||
$this->assertEquals(1234, $group->id);
|
$this->assertEquals(1234, $group->id);
|
||||||
|
|
||||||
app(GroupFake::class)->assertRootFetched();
|
app(GroupFake::class)->assertRootFetched();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_subgroups(): void
|
public function testGetSubgroups(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success(12345, 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup']
|
1234 => ['name' => 'testgroup'],
|
||||||
])->fetches(1234, [
|
])->fetches(1234, [
|
||||||
555 => ['name' => 'ABC']
|
555 => ['name' => 'ABC'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$group = Nami::login(12345, 'secret')->groups(1234)->first();
|
$group = Nami::login(12345, 'secret')->groups(1234)->first();
|
||||||
|
@ -54,13 +52,13 @@ class GroupsTest extends TestCase
|
||||||
app(GroupFake::class)->assertFetched(1234);
|
app(GroupFake::class)->assertFetched(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_needs_authentication(): void
|
public function testNeedsAuthentication(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotAuthenticatedException::class);
|
$this->expectException(NotAuthenticatedException::class);
|
||||||
$group = Nami::group(1234);
|
$group = Nami::group(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_throws_exception_when_group_fetch_failed(): void
|
public function testThrowsExceptionWhenGroupFetchFailed(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NamiException::class);
|
$this->expectException(NamiException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success(12345, 'secret');
|
||||||
|
@ -69,19 +67,19 @@ class GroupsTest extends TestCase
|
||||||
Nami::login(12345, 'secret')->group(1234);
|
Nami::login(12345, 'secret')->group(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_throws_exception_when_subgroup_fetch_failed(): void
|
public function testThrowsExceptionWhenSubgroupFetchFailed(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NamiException::class);
|
$this->expectException(NamiException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success(12345, 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup']
|
1234 => ['name' => 'testgroup'],
|
||||||
]);
|
]);
|
||||||
app(GroupFake::class)->failsToFetch(1234);
|
app(GroupFake::class)->failsToFetch(1234);
|
||||||
|
|
||||||
Nami::login(12345, 'secret')->groups(1234);
|
Nami::login(12345, 'secret')->groups(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_doesnt_return_group_when_no_json_is_returned(): void
|
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success(12345, 'secret');
|
||||||
app(GroupFake::class)->failsToFetchWithoutJson(null);
|
app(GroupFake::class)->failsToFetchWithoutJson(null);
|
||||||
|
@ -89,5 +87,4 @@ class GroupsTest extends TestCase
|
||||||
$group = Nami::login(12345, 'secret')->group(1234);
|
$group = Nami::login(12345, 'secret')->group(1234);
|
||||||
$this->assertNull($group);
|
$this->assertNull($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue