-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
database/factories/ProcessMaker/Models/BookmarkFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Database\Factories\ProcessMaker\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use ProcessMaker\Models\Process; | ||
use ProcessMaker\Models\User; | ||
|
||
/** | ||
* Bookmark factory | ||
*/ | ||
class BookmarkFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'user_id' => function () { | ||
return User::factory()->create()->getKey(); | ||
}, | ||
'process_id' => function () { | ||
return Process::factory()->create()->getKey(); | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Api; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use ProcessMaker\Models\Bookmark; | ||
use ProcessMaker\Models\Process; | ||
use ProcessMaker\Models\User; | ||
use Tests\Feature\Shared\RequestHelper; | ||
use Tests\TestCase; | ||
|
||
class BookmarkTest extends TestCase | ||
{ | ||
use RequestHelper; | ||
|
||
const API_TEST_URL = '/process_bookmarks'; | ||
|
||
const STRUCTURE = [ | ||
'id', | ||
'user_id', | ||
'process_id', | ||
'updated_at', | ||
'created_at', | ||
]; | ||
|
||
/** | ||
* Test get bookmarks | ||
*/ | ||
public function testGetBookmark() | ||
{ | ||
// Create a fake | ||
$bookmark = Bookmark::factory()->count(10)->create(); | ||
$user = User::factory()->create(); | ||
// Call the api GET | ||
$response = $this->apiCall('GET', self::API_TEST_URL); | ||
// Validate the header status code | ||
$response->assertStatus(200); | ||
} | ||
|
||
/** | ||
* Test store bookmarks | ||
*/ | ||
public function testStoreBookmark() | ||
{ | ||
// Create a fake | ||
$process = Process::factory()->create(); | ||
// Call the api POST | ||
$response = $this->apiCall('POST', self::API_TEST_URL .'/'. $process->id, []); | ||
// Validate the header status code | ||
$response->assertStatus(201); | ||
} | ||
|
||
/** | ||
* Test delete bookmark with error 403 | ||
*/ | ||
public function testDeleteBookmark403() | ||
{ | ||
// Create a fake | ||
$process = Process::factory()->create(); | ||
// Call the api DELETE | ||
$response = $this->apiCall('DELETE', self::API_TEST_URL .'/'. $process->id, []); | ||
// Validate the header status code | ||
$response->assertStatus(403); | ||
} | ||
|
||
|
||
/** | ||
* Test delete bookmark | ||
*/ | ||
public function testDeleteBookmark() | ||
{ | ||
// Create a fake | ||
$process = Process::factory()->create(); | ||
$user = User::factory()->create(); | ||
Auth::login($user); | ||
// Call the api POST | ||
$this->apiCall('POST', self::API_TEST_URL .'/'. $process->id, []); | ||
// Call the api DELETE | ||
$response = $this->apiCall('DELETE', self::API_TEST_URL .'/'. $process->id, [ | ||
'user_id' => $user->id | ||
]); | ||
// Validate the header status code | ||
$response->assertStatus(204); | ||
} | ||
} |