1111
1212use Mockery as m ;
1313use Tests \TestCase ;
14- use Ramsey \Uuid \Uuid ;
1514use Pterodactyl \Models \Nest ;
1615use Tests \Traits \MocksUuids ;
1716use Illuminate \Contracts \Config \Repository ;
@@ -25,17 +24,12 @@ class NestCreationServiceTest extends TestCase
2524 /**
2625 * @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
2726 */
28- protected $ config ;
27+ private $ config ;
2928
3029 /**
3130 * @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface|\Mockery\Mock
3231 */
33- protected $ repository ;
34-
35- /**
36- * @var \Pterodactyl\Services\Nests\NestCreationService
37- */
38- protected $ service ;
32+ private $ repository ;
3933
4034 /**
4135 * Setup tests.
@@ -46,8 +40,6 @@ public function setUp()
4640
4741 $ this ->config = m::mock (Repository::class);
4842 $ this ->repository = m::mock (NestRepositoryInterface::class);
49-
50- $ this ->service = new NestCreationService ($ this ->config , $ this ->repository );
5143 }
5244
5345 /**
@@ -56,21 +48,48 @@ public function setUp()
5648 public function testCreateNewService ()
5749 {
5850 $ model = factory (Nest::class)->make ();
59- $ data = [
60- 'name ' => $ model ->name ,
61- 'description ' => $ model ->description ,
62- ];
6351
6452 $ this ->config ->shouldReceive ('get ' )->with ('pterodactyl.service.author ' )->once ()->andReturn ('testauthor@example.com ' );
6553 $ this ->repository ->shouldReceive ('create ' )->with ([
6654 'uuid ' => $ this ->getKnownUuid (),
6755 'author ' => 'testauthor@example.com ' ,
68- 'name ' => $ data ['name ' ],
69- 'description ' => $ data ['description ' ],
56+ 'name ' => $ model ->name ,
57+ 'description ' => $ model ->description ,
58+ ], true , true )->once ()->andReturn ($ model );
59+
60+ $ response = $ this ->getService ()->handle (['name ' => $ model ->name , 'description ' => $ model ->description ]);
61+ $ this ->assertInstanceOf (Nest::class, $ response );
62+ $ this ->assertEquals ($ model , $ response );
63+ }
64+
65+ /**
66+ * Test creation of a new nest with a defined author. This is used by seeder
67+ * scripts which need to set a specific author for nests in order for other
68+ * functionality to work correctly.
69+ */
70+ public function testCreateServiceWithDefinedAuthor ()
71+ {
72+ $ model = factory (Nest::class)->make ();
73+
74+ $ this ->repository ->shouldReceive ('create ' )->with ([
75+ 'uuid ' => $ this ->getKnownUuid (),
76+ 'author ' => 'support@pterodactyl.io ' ,
77+ 'name ' => $ model ->name ,
78+ 'description ' => $ model ->description ,
7079 ], true , true )->once ()->andReturn ($ model );
7180
72- $ response = $ this ->service ->handle ($ data );
81+ $ response = $ this ->getService () ->handle ([ ' name ' => $ model -> name , ' description ' => $ model -> description ], ' support@pterodactyl.io ' );
7382 $ this ->assertInstanceOf (Nest::class, $ response );
7483 $ this ->assertEquals ($ model , $ response );
7584 }
85+
86+ /**
87+ * Return an instance of the service with mocked dependencies.
88+ *
89+ * @return \Pterodactyl\Services\Nests\NestCreationService
90+ */
91+ private function getService (): NestCreationService
92+ {
93+ return new NestCreationService ($ this ->config , $ this ->repository );
94+ }
7695}
0 commit comments