forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateServerScheduleTest.php
More file actions
84 lines (69 loc) · 2.85 KB
/
UpdateServerScheduleTest.php
File metadata and controls
84 lines (69 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Schedule;
use Pterodactyl\Models\Schedule;
use Pterodactyl\Helpers\Utilities;
use Pterodactyl\Models\Permission;
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
{
/**
* Test that a schedule can be updated.
*
* @param array $permissions
* @dataProvider permissionsDataProvider
*/
public function testScheduleCanBeUpdated($permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
$expected = Utilities::getScheduleNextRunDate('5', '*', '*', '*');
$response = $this->actingAs($user)
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}", [
'name' => 'Updated Schedule Name',
'minute' => '5',
'hour' => '*',
'day_of_week' => '*',
'day_of_month' => '*',
'is_active' => false,
]);
$schedule = $schedule->refresh();
$response->assertOk();
$this->assertSame('Updated Schedule Name', $schedule->name);
$this->assertFalse($schedule->is_active);
$this->assertJsonTransformedWith($response->json('attributes'), $schedule);
$this->assertSame($expected->toIso8601String(), $schedule->next_run_at->toIso8601String());
}
/**
* Test that an error is returned if the schedule exists but does not belong to this
* specific server instance.
*/
public function testErrorIsReturnedIfScheduleDoesNotBelongToServer()
{
[$user, $server] = $this->generateTestAccount();
[, $server2] = $this->generateTestAccount(['user_id' => $user->id]);
$schedule = factory(Schedule::class)->create(['server_id' => $server2->id]);
$this->actingAs($user)
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
->assertNotFound();
}
/**
* Test that an error is returned if the subuser does not have permission to modify a
* server schedule.
*/
public function testErrorIsReturnedIfSubuserDoesNotHavePermissionToModifySchedule()
{
[$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_CREATE]);
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
$this->actingAs($user)
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
->assertForbidden();
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];
}
}