Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner committed Jul 13, 2023
1 parent c1aaa79 commit dfcd950
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Http/Controllers/PlatformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
class PlatformController extends Controller
{
/**
* Get platform information.
* Get platform packages.
*/
public function getPlatformInfo(): JsonResponse
public static function getPlatformPackages(): array
{
$installedPackages = collect(InstalledVersions::getInstalledPackages())
->filter(fn ($packageName) => preg_match("/^enjin\/platform-/", $packageName));

$packages = $installedPackages->mapWithKeys(function ($package) {
return $installedPackages->mapWithKeys(function ($package) {
$packageName = Str::studly(Str::afterLast($package, '-'));
if ($packageName == 'Core') {
$packageClass = 'Enjin\\Platform\\Package';
Expand All @@ -35,14 +35,20 @@ public function getPlatformInfo(): JsonResponse
}

return [$package => $info];
});
})->all();
}

/**
* Get platform information.
*/
public function getPlatformInfo(): JsonResponse
{
$platformData = [
'root' => 'enjin/platform-core',
'url' => trim(config('app.url'), '/'),
'chain' => config('enjin-platform.chains.selected'),
'network' => config('enjin-platform.chains.network'),
'packages' => $packages,
'packages' => static::getPlatformPackages(),
];

return response()
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Controllers/PlatformControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Enjin\Platform\Tests\Feature\Controllers;

use Enjin\Platform\Http\Controllers\PlatformController;
use Enjin\Platform\Tests\Feature\GraphQL\TestCaseGraphQL;

class PlatformControllerTest extends TestCaseGraphQL
{
public function test_it_can_get_platform_info(): void
{
$response = $this->json('GET', '/.well-known/enjin-platform.json');
$this->assertTrue($response->getStatusCode() === 200);
$this->assertEquals(
[
'root' => 'enjin/platform-core',
'url' => trim(config('app.url'), '/'),
'chain' => config('enjin-platform.chains.selected'),
'network' => config('enjin-platform.chains.network'),
'packages' => PlatformController::getPlatformPackages(),
],
$response->json()
);
}
}

0 comments on commit dfcd950

Please sign in to comment.