@drummer I don't believe actingAs will help you over an API (I could be wrong). This is how I've generally done this.
/** @test */
public function test_admin_user_can_edit_categories_roles()
{
$user = User::factory()->create(['role_id' => 1]);
// However you do this.
// I typically like putting this method on the User model to make things easy.
$apiToken = $user->generateApiToken();
$data = [
'1' => ['1' => '1'],
'2' => ['1' => '1'],
];
$response = $this->withHeaders(['Authorization' => $apiToken])
->postJson('/admin/connections', $data);
$response->assertCreated();
}
Reading through the Laravel docs more you could also maybe try just adding the guard to your actingAs call: $this->actingAs($user, 'api')
Documented at the bottom of this section: https://laravel.com/docs/8.x/http-tests#session-and-authentication