signIn(); $contact = factory(Contact::class)->create([ 'account_id' => $user->account_id, ]); return [$user, $contact]; } public function test_user_can_add_a_task() { list($user, $contact) = $this->fetchUser(); $taskTitle = $this->faker->realText(); $taskDescription = $this->faker->realText(); $params = [ 'title' => $taskTitle, 'description' => $taskDescription, 'completed' => 0, ]; $response = $this->post('/people/'.$contact->hashID().'/tasks', $params); // Assert the note has been added for the correct user. $params['account_id'] = $user->account_id; $params['contact_id'] = $contact->id; $params['title'] = $taskTitle; $params['description'] = $taskDescription; $this->assertDatabaseHas('tasks', $params); $eventParams = []; // Make sure an event has been created for this action $eventParams['account_id'] = $user->account_id; $eventParams['contact_id'] = $contact->id; $eventParams['object_type'] = 'task'; $eventParams['nature_of_operation'] = 'create'; $this->assertDatabaseHas('events', $eventParams); } }