-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathApiFunctionalityTest.php
More file actions
87 lines (65 loc) · 2.13 KB
/
ApiFunctionalityTest.php
File metadata and controls
87 lines (65 loc) · 2.13 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
85
86
87
<?php
use Cachet\Settings\AppSettings;
use Laravel\Sanctum\Sanctum;
use Workbench\App\User;
use function Pest\Laravel\getJson;
it('has api disabled', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = false;
$settings->api_protected = false;
$settings->save();
getJson('/status/api/ping')
->assertNotFound();
});
it('has api disabled with protected and user', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = false;
$settings->api_protected = true;
$settings->save();
Sanctum::actingAs(User::factory()->create(), ['general.ping']);
getJson('/status/api/ping')
->assertNotFound();
});
it('has api disabled without protected and user', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = false;
$settings->api_protected = true;
$settings->save();
Sanctum::actingAs(User::factory()->create(), ['general.ping']);
getJson('/status/api/ping')
->assertNotFound();
});
it('has public api access', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = true;
$settings->api_protected = false;
$settings->save();
Sanctum::actingAs(User::factory()->create(), ['general.ping']);
getJson('/status/api/ping')
->assertOk();
});
it('has public api access with a user', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = true;
$settings->api_protected = false;
$settings->save();
getJson('/status/api/ping')
->assertOk();
});
it('has no access to api without a user', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = true;
$settings->api_protected = true;
$settings->save();
getJson('/status/api/ping')
->assertUnauthorized();
});
it('has access to api with a user', function () {
$settings = app(AppSettings::class);
$settings->api_enabled = true;
$settings->api_protected = true;
$settings->save();
Sanctum::actingAs(User::factory()->create(), ['general.ping']);
getJson('/status/api/ping')
->assertOk();
});