File tree 2 files changed +47
-0
lines changed
tests/Feature/Depreciations/Api
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -336,6 +336,11 @@ public function deleteCustomFieldsets()
336
336
return $ this ->appendPermission (['customfields.delete ' => '1 ' ]);
337
337
}
338
338
339
+ public function deleteDepreciations ()
340
+ {
341
+ return $ this ->appendPermission (['depreciations.delete ' => '1 ' ]);
342
+ }
343
+
339
344
private function appendPermission (array $ permission )
340
345
{
341
346
return $ this ->state (function ($ currentState ) use ($ permission ) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests \Feature \Depreciations \Api ;
4
+
5
+ use App \Models \Depreciation ;
6
+ use App \Models \User ;
7
+ use Tests \Concerns \TestsPermissionsRequirement ;
8
+ use Tests \TestCase ;
9
+
10
+ class DeleteDepreciationTest extends TestCase implements TestsPermissionsRequirement
11
+ {
12
+ public function testRequiresPermission ()
13
+ {
14
+ $ depreciation = Depreciation::factory ()->create ();
15
+
16
+ $ this ->actingAsForApi (User::factory ()->create ())
17
+ ->deleteJson (route ('api.depreciations.destroy ' , $ depreciation ))
18
+ ->assertForbidden ();
19
+ }
20
+
21
+ public function testCanDeleteDepreciation ()
22
+ {
23
+ $ depreciation = Depreciation::factory ()->create ();
24
+
25
+ $ this ->actingAsForApi (User::factory ()->deleteDepreciations ()->create ())
26
+ ->deleteJson (route ('api.depreciations.destroy ' , $ depreciation ))
27
+ ->assertStatusMessageIs ('success ' );
28
+
29
+ $ this ->assertDatabaseMissing ('depreciations ' , ['id ' => $ depreciation ->id ]);
30
+ }
31
+
32
+ public function testCannotDeleteDepreciationThatHasAssociatedModels ()
33
+ {
34
+ $ depreciation = Depreciation::factory ()->hasModels ()->create ();
35
+
36
+ $ this ->actingAsForApi (User::factory ()->deleteDepreciations ()->create ())
37
+ ->deleteJson (route ('api.depreciations.destroy ' , $ depreciation ))
38
+ ->assertStatusMessageIs ('error ' );
39
+
40
+ $ this ->assertNotNull ($ depreciation ->fresh (), 'Depreciation unexpectedly deleted ' );
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments