diff --git a/tests/Feature/Api/UsersTest.php b/tests/Feature/Api/UsersTest.php index 2e4637c0a5..5eae8fd8d2 100644 --- a/tests/Feature/Api/UsersTest.php +++ b/tests/Feature/Api/UsersTest.php @@ -10,8 +10,6 @@ use ProcessMaker\Models\Process; use ProcessMaker\Models\ProcessRequest; use ProcessMaker\Models\ProcessRequestToken; -use ProcessMaker\Models\ProcessTaskAssignment; -use ProcessMaker\Models\Recommendation; use ProcessMaker\Models\RecommendationUser; use ProcessMaker\Models\Setting; use ProcessMaker\Models\User; @@ -115,6 +113,53 @@ public function testCreateUser() $response->assertStatus(201); } + /** + * Create new user and the email task notification needs to enable per default + */ + public function testFlagEmailTaskNotification() + { + $faker = Faker::create(); + $url = self::API_TEST_URL; + $response = $this->apiCall('POST', $url, [ + 'username' => 'user_test_' . $faker->randomDigit(), + 'firstname' => 'name', + 'lastname' => 'name', + 'email' => $faker->email(), + 'status' => 'ACTIVE', + 'password' => $faker->password(8) . 'A_' . '1', + ]); + + // Test default value email_task_notification was enable + $response->assertStatus(201); + $newUser = $response->json(); + $this->assertEquals(1, $newUser['email_task_notification']); + // Test updating email_task_notification is disable + $userId = $newUser['id']; + $payload = [ + 'username' => $newUser['username'], + 'firstname' => $newUser['firstname'], + 'lastname' => $newUser['lastname'], + 'email' => $newUser['email'], + 'status' => $newUser['status'], + 'email_task_notification' => 0, + ]; + $response = $this->apiCall('PUT', route('api.users.update', $userId), $payload); + $response->assertStatus(204); + // Validate flag email_task_notification was disable + $this->assertDatabaseHas('users', [ + 'email_task_notification' => 0, + ]); + + // Test updating email_task_notification is enable + $payload['email_task_notification'] = 1; + $response = $this->apiCall('PUT', route('api.users.update', $userId), $payload); + $response->assertStatus(204); + // Validate flag email_task_notification was enable + $this->assertDatabaseHas('users', [ + 'email_task_notification' => 0, + ]); + } + public function testCreatePreviouslyDeletedUser() { $url = self::API_TEST_URL; diff --git a/tests/Feature/TaskControllerTest.php b/tests/Feature/TaskControllerTest.php index 31d5fcc990..8924442338 100644 --- a/tests/Feature/TaskControllerTest.php +++ b/tests/Feature/TaskControllerTest.php @@ -4,7 +4,7 @@ use Faker\Factory as Faker; use Illuminate\Support\Facades\Auth; -use ProcessMaker\Models\AnonymousUser; +use ProcessMaker\Facades\WorkflowManager; use ProcessMaker\Models\Process; use ProcessMaker\Models\ProcessAbeRequestToken; use ProcessMaker\Models\ProcessRequest; @@ -146,4 +146,33 @@ public function testReturnMessageTokenNoFound() $response->assertSee('Token not found'); $response->assertStatus(404); } + + /** + * Test email task notification + */ + public function testEmailTaskNotificationInFormTask() + { + $user = User::factory()->create([ + 'email_task_notification' => 1, + ]); + Auth::login($user); + $process = Process::factory()->create([ + 'bpmn' => file_get_contents(__DIR__ . '/../Fixtures/email_task_notification_process.bpmn'), + ]); + // Start a request + $route = route('api.process_events.trigger', [$process->id, 'event' => 'node_1']); + $data = []; + $response = $this->apiCall('POST', $route, $data); + $response->assertStatus(201); + // Find the request + $instance = ProcessRequest::first(); + $task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first(); + $this->assertEquals(0, $task->is_emailsent); + $user = User::where('id', $task->user_id)->first(); + $user->email_task_notification = 1; + $user->save(); + WorkflowManager::completeTask($process, $instance, $task, []); + $task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first(); + $this->assertEquals(0, $task->is_emailsent); + } } diff --git a/tests/Fixtures/email_task_notification_process.bpmn b/tests/Fixtures/email_task_notification_process.bpmn new file mode 100644 index 0000000000..eef0f0394d --- /dev/null +++ b/tests/Fixtures/email_task_notification_process.bpmn @@ -0,0 +1,50 @@ + + + + + node_24 + + + node_24 + node_79 + + + + node_79 + node_83 + + + node_83 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +