-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
21 changed files
with
511 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ DB_PORT=3306 | |
DB_DATABASE=null | ||
DB_USERNAME=null | ||
DB_PASSWORD=null | ||
|
||
[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedIn | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ public function __construct(Asset $asset, $checkedOutTo, User $checkedInBy, $not | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $check | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOu | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $no | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR', '[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public function __construct(Consumable $consumable, $checkedOutTo, User $checked | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $check | |
*/ | ||
public function envelope(): Envelope | ||
{ | ||
$from = new Address(env('MAIL_FROM_ADDR','[email protected]')); | ||
$from = new Address(config('mail.from.address')); | ||
|
||
return new Envelope( | ||
from: $from, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Checkouts\Api; | ||
|
||
use App\Models\Asset; | ||
use App\Models\Company; | ||
use App\Models\Component; | ||
use App\Models\Location; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Tests\Concerns\TestsFullMultipleCompaniesSupport; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$component = Component::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->postJson(route('api.components.checkout', $component->id)) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCannotCheckoutNonExistentComponent() | ||
{ | ||
$this->actingAsForApi(User::factory()->checkoutComponents()->create()) | ||
->postJson(route('api.components.checkout', 1000)) | ||
->assertOk() | ||
->assertStatusMessageIs('error') | ||
->assertMessagesAre('Component does not exist.'); | ||
} | ||
|
||
public function testCheckingOutComponentRequiresValidFields() | ||
{ | ||
$component = Component::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->checkoutComponents()->create()) | ||
->postJson(route('api.components.checkout', $component->id), [ | ||
// | ||
]) | ||
->assertOk() | ||
->assertStatusMessageIs('error') | ||
->assertPayloadContains('assigned_to') | ||
->assertPayloadContains('assigned_qty'); | ||
} | ||
|
||
public function testCannotCheckoutComponentIfRequestedAmountIsMoreThanComponentQuantity() | ||
{ | ||
$asset = Asset::factory()->create(); | ||
$component = Component::factory()->create(['qty' => 2]); | ||
|
||
$this->actingAsForApi(User::factory()->checkoutComponents()->create()) | ||
->postJson(route('api.components.checkout', $component->id), [ | ||
'assigned_to' => $asset->id, | ||
'assigned_qty' => 3, | ||
]) | ||
->assertOk() | ||
->assertStatusMessageIs('error') | ||
->assertMessagesAre(trans('admin/components/message.checkout.unavailable', ['remaining' => 2, 'requested' => 3])); | ||
} | ||
|
||
public function testCannotCheckoutComponentIfRequestedAmountIsMoreThanWhatIsRemaining() | ||
{ | ||
$asset = Asset::factory()->create(); | ||
$component = Component::factory()->create(['qty' => 2]); | ||
$component->assets()->attach($component->id, [ | ||
'component_id' => $component->id, | ||
'created_at' => Carbon::now(), | ||
'assigned_qty' => 1, | ||
'asset_id' => $asset->id, | ||
]); | ||
|
||
$this->actingAsForApi(User::factory()->checkoutComponents()->create()) | ||
->postJson(route('api.components.checkout', $component->id), [ | ||
'assigned_to' => $asset->id, | ||
'assigned_qty' => 3, | ||
]) | ||
->assertOk() | ||
->assertStatusMessageIs('error'); | ||
} | ||
|
||
public function testCanCheckoutComponent() | ||
{ | ||
$user = User::factory()->checkoutComponents()->create(); | ||
$asset = Asset::factory()->create(); | ||
$component = Component::factory()->create(); | ||
|
||
$this->actingAsForApi($user) | ||
->postJson(route('api.components.checkout', $component->id), [ | ||
'assigned_to' => $asset->id, | ||
'assigned_qty' => 1, | ||
]) | ||
->assertOk() | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertTrue($component->assets->first()->is($asset)); | ||
} | ||
|
||
public function testComponentCheckoutIsLogged() | ||
{ | ||
$user = User::factory()->checkoutComponents()->create(); | ||
$location = Location::factory()->create(); | ||
$asset = Asset::factory()->create(['location_id' => $location->id]); | ||
$component = Component::factory()->create(); | ||
|
||
$this->actingAsForApi($user) | ||
->postJson(route('api.components.checkout', $component->id), [ | ||
'assigned_to' => $asset->id, | ||
'assigned_qty' => 1, | ||
]); | ||
|
||
$this->assertDatabaseHas('action_logs', [ | ||
'created_by' => $user->id, | ||
'action_type' => 'checkout', | ||
'target_id' => $asset->id, | ||
'target_type' => Asset::class, | ||
'location_id' => $location->id, | ||
'item_type' => Component::class, | ||
'item_id' => $component->id, | ||
]); | ||
} | ||
|
||
public function testAdheresToFullMultipleCompaniesSupportScoping() | ||
{ | ||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
|
||
$userForCompanyA = User::factory()->for($companyA)->create(); | ||
$assetForCompanyB = Asset::factory()->for($companyB)->create(); | ||
$componentForCompanyB = Component::factory()->for($companyB)->create(); | ||
|
||
$this->actingAsForApi($userForCompanyA) | ||
->postJson(route('api.components.checkout', $componentForCompanyB->id), [ | ||
'assigned_to' => $assetForCompanyB->id, | ||
'assigned_qty' => 1, | ||
]) | ||
->assertForbidden(); | ||
} | ||
} |
Oops, something went wrong.