Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>

# Conflicts:
#	.all-contributorsrc
#	CONTRIBUTORS.md
  • Loading branch information
snipe committed Jul 16, 2024
2 parents 39810f9 + 35160f8 commit 0a70bcc
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 68 deletions.
9 changes: 4 additions & 5 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3147,14 +3147,13 @@
]
},
{
"login": "Galaxy102",
"name": "Konstantin Köhring",
"avatar_url": "https://avatars.githubusercontent.com/u/18245993?v=4",
"profile": "https://www.galaxy102.de",
"login": "dbakan",
"name": "Daniel Albertsen",
"avatar_url": "https://avatars.githubusercontent.com/u/4498077?v=4",
"profile": "https://ditscheri.com",
"contributions": [
"code"
]
}

]
}
100 changes: 50 additions & 50 deletions CONTRIBUTORS.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public function getAssetByTag(Request $request, $tag=null) : RedirectResponse
* @param int $assetId
* @since [v1.0]
*/
public function getQrCode($assetId = null) : Response | BinaryFileResponse
public function getQrCode($assetId = null) : Response | BinaryFileResponse | string | bool
{
$settings = Setting::getSettings();

Expand All @@ -502,6 +502,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse

return 'That asset is invalid';
}
return false;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,28 +549,28 @@
Api\AssetFilesController::class,
'store'
]
)->name('api.assets.files');
)->name('api.assets.files.store');

Route::get('{asset_id}/files',
[
Api\AssetFilesController::class,
'list'
]
)->name('api.assets.files');
)->name('api.assets.files.index');

Route::get('{asset_id}/file/{file_id}',
[
Api\AssetFilesController::class,
'show'
]
)->name('api.assets.file');
)->name('api.assets.files.show');

Route::delete('{asset_id}/file/{file_id}',
[
Api\AssetFilesController::class,
'destroy'
]
)->name('api.assets.file');
)->name('api.assets.files.destroy');

});

Expand Down
16 changes: 8 additions & 8 deletions tests/Feature/Assets/Api/AssetFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testAssetApiAcceptsFileUpload()
//Upload a file
$this->actingAsForApi($user)
->post(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
])
->assertOk();
Expand All @@ -41,7 +41,7 @@ public function testAssetApiListsFiles()
// List the files
$this->actingAsForApi($user)
->getJson(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]))
route('api.assets.files.index', ['asset_id' => $asset[0]["id"]]))
->assertOk()
->assertJsonStructure([
'status',
Expand All @@ -63,21 +63,21 @@ public function testAssetApiDownloadsFile()
//Upload a file
$this->actingAsForApi($user)
->post(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
])
->assertOk();

// List the files to get the file ID
$result = $this->actingAsForApi($user)
->getJson(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]))
route('api.assets.files.index', ['asset_id' => $asset[0]["id"]]))
->assertOk();

// Get the file
$this->actingAsForApi($user)
->get(
route('api.assets.file', [
route('api.assets.files.show', [
'asset_id' => $asset[0]["id"],
'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"],
]))
Expand All @@ -97,21 +97,21 @@ public function testAssetApiDeletesFile()
//Upload a file
$this->actingAsForApi($user)
->post(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
])
->assertOk();

// List the files to get the file ID
$result = $this->actingAsForApi($user)
->getJson(
route('api.assets.files', ['asset_id' => $asset[0]["id"]]))
route('api.assets.files.index', ['asset_id' => $asset[0]["id"]]))
->assertOk();

// Delete the file
$this->actingAsForApi($user)
->delete(
route('api.assets.file', [
route('api.assets.files.destroy', [
'asset_id' => $asset[0]["id"],
'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"],
]))
Expand Down
14 changes: 14 additions & 0 deletions tests/Feature/Console/OptimizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\Feature\Console;

use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;

class OptimizeTest extends TestCase
{
public function testOptimizeSucceeds()
{
$this->artisan('optimize')->assertSuccessful();
}
}
61 changes: 61 additions & 0 deletions tests/Feature/Reporting/UnacceptedAssetReportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Tests\Feature\Reporting;

use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
use Illuminate\Testing\TestResponse;
use League\Csv\Reader;
use PHPUnit\Framework\Assert;
use Tests\TestCase;

class UnacceptedAssetReportTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

TestResponse::macro(
'assertSeeTextInStreamedResponse',
function (string $needle) {
Assert::assertTrue(
collect(Reader::createFromString($this->streamedContent())->getRecords())
->pluck(0)
->contains($needle)
);

return $this;
}
);

TestResponse::macro(
'assertDontSeeTextInStreamedResponse',
function (string $needle) {
Assert::assertFalse(
collect(Reader::createFromString($this->streamedContent())->getRecords())
->pluck(0)
->contains($needle)
);

return $this;
}
);
}


public function testPermissionRequiredToViewUnacceptedAssetReport()
{
$this->actingAs(User::factory()->create())
->get(route('reports/unaccepted_assets'))
->assertForbidden();
}

public function testUserCanListUnacceptedAssets()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('reports/unaccepted_assets'))
->assertOk();
}

}

0 comments on commit 0a70bcc

Please sign in to comment.