Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions tests/Feature/Api/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 30 additions & 1 deletion tests/Feature/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
50 changes: 50 additions & 0 deletions tests/Fixtures/email_task_notification_process.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:pm="http://processmaker.com/BPMN/2.0/Schema.xsd" xmlns:tns="http://sourceforge.net/bpmn/definitions/_1530553328908" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL http://bpmn.sourceforge.net/schemas/BPMN20.xsd">
<bpmn:process id="ProcessId" name="ProcessName" isExecutable="true">
<bpmn:startEvent id="node_1" name="Start Event" pm:allowInterstitial="true" pm:interstitialScreenRef="1">
<bpmn:outgoing>node_24</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="node_2" name="Form Task A" pm:allowInterstitial="false" pm:assignment="requester" pm:assignmentLock="false" pm:allowReassignment="false" pm:elementDestination="{&#34;type&#34;:&#34;taskSource&#34;,&#34;value&#34;:null}">
<bpmn:incoming>node_24</bpmn:incoming>
<bpmn:outgoing>node_79</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="node_24" sourceRef="node_1" targetRef="node_2" />
<bpmn:task id="node_61" name="Form Task B" pm:allowInterstitial="false" pm:assignment="requester" pm:assignmentLock="false" pm:allowReassignment="false" pm:elementDestination="{&#34;type&#34;:&#34;taskSource&#34;,&#34;value&#34;:null}">
<bpmn:incoming>node_79</bpmn:incoming>
<bpmn:outgoing>node_83</bpmn:outgoing>
</bpmn:task>
<bpmn:endEvent id="node_71" name="End Event" pm:elementDestination="{&#34;type&#34;:&#34;summaryScreen&#34;,&#34;value&#34;:null}">
<bpmn:incoming>node_83</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="node_79" sourceRef="node_2" targetRef="node_61" />
<bpmn:sequenceFlow id="node_83" sourceRef="node_61" targetRef="node_71" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagramId">
<bpmndi:BPMNPlane id="BPMNPlaneId" bpmnElement="ProcessId">
<bpmndi:BPMNShape id="node_1_di" bpmnElement="node_1">
<dc:Bounds x="270" y="160" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="391" y="142" width="116" height="76" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="node_24_di" bpmnElement="node_24">
<di:waypoint x="288" y="178" />
<di:waypoint x="449" y="180" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="node_61_di" bpmnElement="node_61">
<dc:Bounds x="584" y="144" width="116" height="76" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_71_di" bpmnElement="node_71">
<dc:Bounds x="760" y="160" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="node_79_di" bpmnElement="node_79">
<di:waypoint x="449" y="180" />
<di:waypoint x="642" y="182" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="node_83_di" bpmnElement="node_83">
<di:waypoint x="642" y="182" />
<di:waypoint x="778" y="178" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>