mutation = ' mutation($entryId: Int!, $videoId: Int!) { Watch(entryId: $entryId, videoId: $videoId) { animethemeentry { id } video { id } } } '; }); test('protected', function (): void { $response = $this->graphQL( $this->mutation, [ 'entryId' => fake()->randomDigitNotNull(), 'videoId' => fake()->randomDigitNotNull(), ], ); $response->assertOk(); $response->assertJsonPath('errors.0.message', 'Unauthenticated.'); }); test('forbidden', function (): void { actingAs(User::factory()->createOne()); $response = $this->graphQL( $this->mutation, [ 'entryId' => fake()->randomDigitNotNull(), 'videoId' => fake()->randomDigitNotNull(), ], ); $response->assertOk(); $response->assertJsonPath('errors.0.message', 'This action is unauthorized.'); }); test('invalid entry id or video id', function (): void { $user = User::factory() ->withPermissions(CrudPermission::CREATE->format(WatchHistory::class)) ->createOne(); actingAs($user); $entry = AnimeThemeEntry::factory()->createOne(); $video = Video::factory()->createOne(); $response = $this->graphQL( $this->mutation, [ 'entryId' => $entry->getKey(), 'videoId' => $video->getKey(), ], ); $response->assertOk(); $response->assertGraphQLValidationKeys(['entryId', 'videoId']); }); test('mark as watched', function (): void { $user = User::factory() ->withPermissions(CrudPermission::CREATE->format(WatchHistory::class)) ->createOne(); actingAs($user); $entry = AnimeThemeEntry::factory()->createOne(); $video = Video::factory()->createOne(); $entry->videos()->attach($video); $response = $this->graphQL( $this->mutation, [ 'entryId' => $entry->getKey(), 'videoId' => $video->getKey(), ], ); $this->assertDatabaseCount(WatchHistory::class, 1); $response->assertOk(); $response->assertJson([ 'data' => [ 'Watch' => [ 'animethemeentry' => [ 'id' => $entry->getKey(), ], 'video' => [ 'id' => $video->getKey(), ], ], ], ]); });