diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 9e262a1f..dabd5e7b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; +use Laravel\Telescope\Telescope; use Zoomyboy\LaravelNami\Authentication\NamiGuard; class AppServiceProvider extends ServiceProvider @@ -19,6 +20,7 @@ class AppServiceProvider extends ServiceProvider public function register() { JsonResource::withoutWrapping(); + Telescope::ignoreMigrations(); \Inertia::share('search', request()->query('search', '')); diff --git a/database/migrations/2017_07_05_000438_create_genders_table.php b/database/migrations/2017_07_05_000438_create_genders_table.php index 3fc4a3b9..c388f99b 100644 --- a/database/migrations/2017_07_05_000438_create_genders_table.php +++ b/database/migrations/2017_07_05_000438_create_genders_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); - $table->integer('nami_id'); + $table->unsignedInteger('nami_id'); $table->timestamps(); }); } diff --git a/database/migrations/2017_07_05_000810_create_regions_table.php b/database/migrations/2017_07_05_000810_create_regions_table.php index 7f1fc67f..5ed05994 100644 --- a/database/migrations/2017_07_05_000810_create_regions_table.php +++ b/database/migrations/2017_07_05_000810_create_regions_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); $table->boolean('is_null'); - $table->integer('nami_id')->nullable(); + $table->unsignedInteger('nami_id')->nullable(); }); } diff --git a/database/migrations/2017_07_05_001729_create_confessions_table.php b/database/migrations/2017_07_05_001729_create_confessions_table.php index 983614a2..b74eedc2 100644 --- a/database/migrations/2017_07_05_001729_create_confessions_table.php +++ b/database/migrations/2017_07_05_001729_create_confessions_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); - $table->integer('nami_id')->nullable(); + $table->unsignedInteger('nami_id')->nullable(); $table->boolean('is_null'); }); } diff --git a/database/migrations/2018_01_22_235143_create_subscriptions_table.php b/database/migrations/2018_01_22_235143_create_subscriptions_table.php index acd55b50..edf8f9bc 100644 --- a/database/migrations/2018_01_22_235143_create_subscriptions_table.php +++ b/database/migrations/2018_01_22_235143_create_subscriptions_table.php @@ -1,8 +1,8 @@ schema = Schema::connection($this->getConnection()); + } + + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + $this->schema->create('telescope_entries', function (Blueprint $table) { + $table->bigIncrements('sequence'); + $table->uuid('uuid'); + $table->uuid('batch_id'); + $table->string('family_hash')->nullable(); + $table->boolean('should_display_on_index')->default(true); + $table->string('type', 20); + $table->longText('content'); + $table->dateTime('created_at')->nullable(); + + $table->unique('uuid'); + $table->index('batch_id'); + $table->index('family_hash'); + $table->index('created_at'); + $table->index(['type', 'should_display_on_index']); + }); + + $this->schema->create('telescope_entries_tags', function (Blueprint $table) { + $table->uuid('entry_uuid'); + $table->string('tag'); + + $table->index(['entry_uuid', 'tag']); + $table->index('tag'); + + $table->foreign('entry_uuid') + ->references('uuid') + ->on('telescope_entries') + ->onDelete('cascade'); + }); + + $this->schema->create('telescope_monitoring', function (Blueprint $table) { + $table->string('tag'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $this->schema->dropIfExists('telescope_entries_tags'); + $this->schema->dropIfExists('telescope_entries'); + $this->schema->dropIfExists('telescope_monitoring'); + } +} diff --git a/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php b/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php index c3f1ba91..90d00ff0 100644 --- a/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php +++ b/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php @@ -1,11 +1,11 @@ foreignId('fee_id')->after('name')->constrained(); }); - foreach(Fee::get() as $fee) { - Subscription::create([ - 'amount' => 1000, - 'fee_id' => $fee->id, - 'name' => $fee->name, - ]); - } - Schema::table('members', function (Blueprint $table) { $table->foreignId('subscription_id')->after('version')->nullable()->default(1)->constrained(); }); - Member::withoutEvents(function() { - foreach (Member::get() as $member) { - if (is_null($member->fee_id)) { - $member->update(['subscription_id' => null]); - continue; - } - - $member->update(['subscription_id' => Subscription::firstWhere('fee_id', $member->fee_id)->id]); - } - }); - Schema::table('members', function (Blueprint $table) { $table->dropForeign(['fee_id']); $table->dropColumn('fee_id'); diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index b93275c1..953aeadc 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -1,5 +1,6 @@ create([ + User::factory()->create([ 'email' => 'admin@example.com', 'email_verified_at' => now(), 'password' => Hash::make('admin') diff --git a/database/settings/2021_11_18_230152_create_general_settings.php b/database/settings/2021_11_18_230152_create_general_settings.php index 6aed4a83..1fd9f7b1 100644 --- a/database/settings/2021_11_18_230152_create_general_settings.php +++ b/database/settings/2021_11_18_230152_create_general_settings.php @@ -7,7 +7,7 @@ class CreateGeneralSettings extends SettingsMigration /** * @param string $mode - * @return array + * @return array|bool> */ public function defaults(string $mode): array { diff --git a/tests/Feature/Member/IndexTest.php b/tests/Feature/Member/IndexTest.php index fffa3c91..b30e55fa 100644 --- a/tests/Feature/Member/IndexTest.php +++ b/tests/Feature/Member/IndexTest.php @@ -37,9 +37,12 @@ class IndexTest extends TestCase ]); $this->withoutExceptionHandling(); $this->login(); + Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname::']); - Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname']); - $this->get('/member')->assertInertia('member/Index', ['firstname' => '::firstname'], 'data.data.0'); + $response = $this->get('/member'); + + $this->assertComponent('member/Index', $response); + $this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname'); } } diff --git a/tests/Feature/Settings/GlobalSettingTest.php b/tests/Feature/Settings/GlobalSettingTest.php index f18a61f6..120111b1 100644 --- a/tests/Feature/Settings/GlobalSettingTest.php +++ b/tests/Feature/Settings/GlobalSettingTest.php @@ -22,8 +22,8 @@ class GlobalSettingTest extends TestCase $response = $this->get('/setting'); - $response->assertInertiaComponent('setting/Index'); - $this->assertEquals(['bill'], $response->inertia('general.modules')); + $this->assertComponent('setting/Index', $response); + $this->assertEquals(['bill'], $this->inertia($response, 'general.modules')); } public function testItGetsOptionsForModels(): void @@ -33,7 +33,7 @@ class GlobalSettingTest extends TestCase $response = $this->get('/setting'); - $this->assertContains('bill', $response->inertia('options.modules')); + $this->assertContains('bill', $this->inertia($response, 'options.modules')); } } diff --git a/tests/Lib/InertiaMixin.php b/tests/Lib/InertiaMixin.php deleted file mode 100644 index b2722b8c..00000000 --- a/tests/Lib/InertiaMixin.php +++ /dev/null @@ -1,128 +0,0 @@ -viewData('page')['component']); - - $this->assertInertiaHas($props, $key); - - return $this; - }; - } - - public function assertInertiaComponent() { - return function($component) { - PHPUnit::assertEquals($component, $this->viewData('page')['component']); - - return $this; - }; - } - - public function assertInertiaHasShared() { - return function($bindings, $key = null) { - $bindings = json_decode(json_encode($bindings), true); - - $viewData = json_decode(json_encode( - data_get($this->viewData('page'), $key) - ), true); - - $this->assertDeepNest($bindings, $viewData); - }; - } - - public function assertInertiaHas() { - return function($bindings, $key = null) { - $bindings = json_decode(json_encode($bindings), true); - - $viewData = json_decode(json_encode( - data_get($this->viewData('page')['props'], $key) - ), true); - - $bindings = is_array($bindings) ? $bindings : [$bindings]; - $viewData = is_array($viewData) ? $viewData : [$viewData]; - - $this->assertDeepNest($bindings, $viewData); - }; - } - - public function assertDeepNest() { - return function($should, $is) { - foreach ($should as $key => $value) { - PHPUnit::assertArrayHasKey($key, $is); - - if (is_array($value)) { - $this->assertDeepNest($value, $is[$key]); - continue; - } - - PHPUnit::assertSame($value, $is[$key]); - } - }; - } - - public function assertInertiaHasItem() { - - return function($should, $nestedKey) { - $is = data_get($this->viewData('page')['props'], $nestedKey); - $is = collect(json_decode(json_encode($is), true)); - - $should = collect(json_decode(json_encode($should), true)); - - $has = $is->contains(function($isItem) use ($should) { - return $this->isDeepEqual($should, Collection::wrap($isItem)); - }); - - PHPUnit::assertTrue($has, 'Failed asserting that inertia attribute '.$nestedKey.' has Data '.print_r($should, true)); - - return $this; - }; - - } - - public function inertia() { - return function($item) { - return data_get($this->viewData('page')['props'], $item); - }; - } - - public function assertInertiaEquals() { - return function($should, $nestedKey) { - $is = data_get($this->viewData('page')['props'], $nestedKey); - - PHPUnit::assertSame($should, $is); - - return $this; - }; - } - - public function ddp() { - return function ($value) { - dd(data_get($this->viewData('page'), $value)); - }; - } - - public function ddi() { - return function ($value) { - dd(data_get($this->viewData('page')['props'], $value)); - }; - } - - public function isDeepEqual() { - return function (Collection $subset, Collection $compare) { - $subset = $subset->filter(fn($item) => !is_array($item)); - $compare = $compare->filter(fn($item) => !is_array($item)); - - return $subset->diffAssoc($compare)->isEmpty(); - }; - } - -} - diff --git a/tests/Lib/TestsInertia.php b/tests/Lib/TestsInertia.php new file mode 100644 index 00000000..a805624d --- /dev/null +++ b/tests/Lib/TestsInertia.php @@ -0,0 +1,42 @@ +viewData('page')['props'], $key) + ), true); + $bindings = is_array($bindings) ? $bindings : [$bindings]; + $viewData = is_array($viewData) ? $viewData : [$viewData]; + $this->assertInertiaDeepNest($bindings, $viewData); + } + + public function assertComponent(string $component, TestResponse $response) { + PHPUnit::assertEquals($component, $response->viewData('page')['component']); + } + + public function assertInertiaDeepNest($should, $is) { + foreach ($should as $key => $value) { + PHPUnit::assertArrayHasKey($key, $is); + + if (is_array($value)) { + $this->assertInertiaDeepNest($value, $is[$key]); + continue; + } + + PHPUnit::assertSame($value, $is[$key]); + } + } + + public function inertia(TestResponse $response, string $key) { + return data_get($response->viewData('page')['props'], $key); + } + +} diff --git a/tests/TestCase.php b/tests/TestCase.php index ccdb63bb..45245a14 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,7 @@ use App\Member\Member; use App\Setting\GeneralSettings; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Testing\TestResponse; -use Tests\Lib\InertiaMixin; +use Tests\Lib\TestsInertia; use Zoomyboy\LaravelNami\Backend\FakeBackend; use Zoomyboy\LaravelNami\Nami; use Zoomyboy\LaravelNami\NamiUser; @@ -14,12 +14,7 @@ use Zoomyboy\LaravelNami\NamiUser; abstract class TestCase extends BaseTestCase { use CreatesApplication; - - public function setUp(): void { - parent::setUp(); - - TestResponse::mixin(new InertiaMixin()); - } + use TestsInertia; public function fakeAuthUser() { app(FakeBackend::class)