create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $action = new UploadVideoAction($file, $this->faker->word()); $storageResults = $action->handle(); $result = $storageResults->toActionResult(); static::assertTrue($result->hasFailed()); } /** * The Upload Video Action shall pass if given a valid file. * * @return void */ public function testPassed(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $action = new UploadVideoAction($file, $this->faker->word()); $storageResults = $action->handle(); $result = $storageResults->toActionResult(); static::assertTrue(ActionStatus::PASSED === $result->getStatus()); } /** * The Upload Video Action shall upload the file to the configured disk. * * @return void */ public function testUploadedToDisk(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $action = new UploadVideoAction($file, $this->faker->word()); $action->handle(); static::assertCount(1, Storage::disk(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED))->allFiles()); } /** * The Upload Video Action shall upload the file to the configured disk. * * @return void * * @throws Exception */ public function testCreatedVideo(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $action = new UploadVideoAction($file, $this->faker->word()); $result = $action->handle(); $action->then($result); static::assertDatabaseCount(Video::class, 1); } /** * The Upload Video Action shall set additional video attributes. * * @return void * * @throws Exception */ public function testSetsAttributes(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $overlap = Arr::random(VideoOverlap::cases()); $source = Arr::random(VideoSource::cases()); $attributes = [ Video::ATTRIBUTE_RESOLUTION => $this->faker->numberBetween(360, 1080), Video::ATTRIBUTE_NC => $this->faker->boolean(), Video::ATTRIBUTE_SUBBED => $this->faker->boolean(), Video::ATTRIBUTE_LYRICS => $this->faker->boolean(), Video::ATTRIBUTE_UNCEN => $this->faker->boolean(), Video::ATTRIBUTE_OVERLAP => $overlap->value, Video::ATTRIBUTE_SOURCE => $source->value, ]; $action = new UploadVideoAction($file, $this->faker->word(), $attributes); $result = $action->handle(); $action->then($result); static::assertDatabaseHas(Video::class, $attributes); } /** * The Upload Video Action shall attach the provided entry. * * @return void * * @throws Exception */ public function testAttachesEntry(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $entry = AnimeThemeEntry::factory() ->for(AnimeTheme::factory()->for(Anime::factory())) ->createOne(); $action = new UploadVideoAction(file: $file, path: $this->faker->word(), entry: $entry); $result = $action->handle(); $action->then($result); static::assertDatabaseCount(AnimeThemeEntryVideo::class, 1); } /** * The Upload Video Action shall attach the provided script. * * @return void * * @throws Exception */ public function testAssociatesScript(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Config::set(VideoConstants::DISKS_QUALIFIED, [Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)]); Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull()); $script = File::fake()->create($this->faker->word().'.txt', $this->faker->randomDigitNotNull()); $action = new UploadVideoAction(file: $file, path: $this->faker->word(), script: $script); $result = $action->handle(); $action->then($result); static::assertDatabaseHas(VideoScript::class, [VideoScript::ATTRIBUTE_VIDEO => 1]); } }