مجید
4 سال پیش توسط مجید مطرح شد
0 پاسخ

این تست درسته

سلام.
به سوال راجع به تست نویسی داشتم

به نظرتون این تست تست درستی هست؟

   public function it_shows_list_of_videos(): void
    {
        $user = User::factory()->create();

        Video::factory()->count(5)->create();

        $resp = $this->actingAs($user)
            ->json('GET', route('video.list'));

      $resp->assertJson(function (AssertableJson $json) {
            $json->where('total', 5)
                ->has('data', 5)
                ->etc();
        });
    }

وقتی کد

        $resp = $this->actingAs($user)
            ->json('GET', route('video.list'));

اجرا بشه دیگه مهم نیست کد

 Video::factory()->count(5)->create();

چی باشه
درسته؟

این هم api

    Route::get('/videos/list', [VideoController::class, 'index'])->name('video.list');

این هم controller

    public function index(): Response
    {
        $videos = Video::query()
            ->published()
            ->orderByDesc('created_at')
            ->paginate(10);
        return response($videos, 200);
    }