mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-02-24 11:13:02 +01:00
Refactor API tests with simplified request authentication (#6)
Also fixes issues with the update requests checks for unique values
This commit is contained in:
parent
c586134862
commit
6e95f98396
@ -30,7 +30,12 @@ class LinkUpdateRequest extends FormRequest
|
||||
{
|
||||
$this->isApiRequest = $request->isJson();
|
||||
|
||||
$this->requireUniqueUrl = Link::urlHasChanged($request->route('link'), $request->input('url', ''));
|
||||
if ($request->input('url') !== null) {
|
||||
$this->requireUniqueUrl = Link::urlHasChanged(
|
||||
$request->route('link'),
|
||||
$request->input('url')
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,7 +25,12 @@ class ListUpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
$this->requireUniqueName = LinkList::nameHasChanged($request->route('list'), $request->input('name', ''));
|
||||
if ($request->input('name') !== null) {
|
||||
$this->requireUniqueName = LinkList::nameHasChanged(
|
||||
$request->route('list'),
|
||||
$request->input('name')
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,7 +25,12 @@ class TagUpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
$this->requireUniqueName = Tag::nameHasChanged($request->route('tag'), $request->input('name', ''));
|
||||
if ($request->input('name') !== null) {
|
||||
$this->requireUniqueName = Tag::nameHasChanged(
|
||||
$request->route('tag'),
|
||||
$request->input('name')
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ namespace Tests\Controller\API;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\TestCase;
|
||||
|
||||
abstract class ApiTestCase extends TestCase
|
||||
@ -19,6 +21,7 @@ abstract class ApiTestCase extends TestCase
|
||||
$this->user = factory(User::class)->create();
|
||||
|
||||
Queue::fake();
|
||||
Notification::fake();
|
||||
|
||||
$testHtml = '<!DOCTYPE html><head>' .
|
||||
'<title>Example Title</title>' .
|
||||
@ -30,10 +33,58 @@ abstract class ApiTestCase extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
protected function generateHeaders(): array
|
||||
/**
|
||||
* Send an authorized JSON request for the GET method.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $headers
|
||||
* @return TestResponse
|
||||
*/
|
||||
public function getJsonAuthorized($uri, array $headers = []): TestResponse
|
||||
{
|
||||
return [
|
||||
'Authorization' => 'Bearer ' . $this->user->api_token,
|
||||
];
|
||||
$headers['Authorization'] = 'Bearer ' . $this->user->api_token;
|
||||
return $this->getJson($uri, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an authorized JSON request for the POST method.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @return TestResponse
|
||||
*/
|
||||
public function postJsonAuthorized($uri, array $data = [], array $headers = []): TestResponse
|
||||
{
|
||||
$headers['Authorization'] = 'Bearer ' . $this->user->api_token;
|
||||
return $this->postJson($uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an authorized JSON request for the PATCH method.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @return TestResponse
|
||||
*/
|
||||
public function patchJsonAuthorized($uri, array $data = [], array $headers = []): TestResponse
|
||||
{
|
||||
$headers['Authorization'] = 'Bearer ' . $this->user->api_token;
|
||||
return $this->patchJson($uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an authorized JSON request for the DELETE method.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @return TestResponse
|
||||
*/
|
||||
public function deleteJsonAuthorized($uri, array $data = [], array $headers = []): TestResponse
|
||||
{
|
||||
$headers['Authorization'] = 'Bearer ' . $this->user->api_token;
|
||||
return $this->deleteJson($uri, $data, $headers);
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ class LinkApiTest extends ApiTestCase
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['url' => $link->url],
|
||||
@ -38,11 +38,11 @@ class LinkApiTest extends ApiTestCase
|
||||
|
||||
public function testMinimalCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/links', [
|
||||
$response = $this->postJsonAuthorized('api/v1/links', [
|
||||
'url' => 'http://example.com',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'url' => 'http://example.com',
|
||||
]);
|
||||
@ -57,7 +57,7 @@ class LinkApiTest extends ApiTestCase
|
||||
$list = factory(LinkList::class)->create();
|
||||
$tag = factory(Tag::class)->create();
|
||||
|
||||
$response = $this->postJson('api/v1/links', [
|
||||
$response = $this->postJsonAuthorized('api/v1/links', [
|
||||
'url' => 'http://example.com',
|
||||
'title' => 'Search the Web',
|
||||
'description' => 'There could be a description here',
|
||||
@ -65,9 +65,9 @@ class LinkApiTest extends ApiTestCase
|
||||
'tags' => [$tag->id],
|
||||
'is_private' => false,
|
||||
'check_disabled' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'url' => 'http://example.com',
|
||||
]);
|
||||
@ -81,31 +81,30 @@ class LinkApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/links', [
|
||||
$response = $this->postJsonAuthorized('api/v1/links', [
|
||||
'url' => null,
|
||||
'lists' => 'no array',
|
||||
'tags' => 123,
|
||||
'is_private' => 'hello',
|
||||
'check_disabled' => 'bla',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'url',
|
||||
'lists',
|
||||
'tags',
|
||||
'is_private',
|
||||
'check_disabled',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'url' => 'The url field is required.',
|
||||
'lists' => 'The lists must be an array.',
|
||||
'tags' => 'The tags must be an array.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
'check_disabled' => 'The check disabled field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testShowRequest(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/links/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'url' => $link->url,
|
||||
]);
|
||||
@ -120,9 +119,9 @@ class LinkApiTest extends ApiTestCase
|
||||
$link->lists()->sync([$list->id]);
|
||||
$link->tags()->sync([$tag->id]);
|
||||
|
||||
$response = $this->getJson('api/v1/links/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'url' => $link->url,
|
||||
'lists' => [
|
||||
@ -136,26 +135,26 @@ class LinkApiTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/links/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testUpdateRequest(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
factory(Link::class)->create();
|
||||
$list = factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/links/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/links/1', [
|
||||
'url' => 'http://example.com',
|
||||
'title' => 'Custom Title',
|
||||
'description' => 'Custom Description',
|
||||
'lists' => [$list->id],
|
||||
'is_private' => false,
|
||||
'check_disabled' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'url' => 'http://example.com',
|
||||
]);
|
||||
@ -167,21 +166,28 @@ class LinkApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidUpdateRequest(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
factory(Link::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/links/1', [
|
||||
//
|
||||
], $this->generateHeaders());
|
||||
$response = $this->patchJsonAuthorized('api/v1/links/1', [
|
||||
'url' => null,
|
||||
'lists' => 'no array',
|
||||
'tags' => 123,
|
||||
'is_private' => 'hello',
|
||||
'check_disabled' => 'bla',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'url',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'url' => 'The url field is required.',
|
||||
'lists' => 'The lists must be an array.',
|
||||
'tags' => 'The tags must be an array.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
'check_disabled' => 'The check disabled field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateRequestNotFound(): void
|
||||
{
|
||||
$response = $this->patchJson('api/v1/links/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/links/1', [
|
||||
'url' => 'http://example.com',
|
||||
'title' => 'Custom Title',
|
||||
'description' => 'Custom Description',
|
||||
@ -189,26 +195,26 @@ class LinkApiTest extends ApiTestCase
|
||||
'tags' => [],
|
||||
'is_private' => false,
|
||||
'check_disabled' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testDeleteRequest(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
factory(Link::class)->create();
|
||||
|
||||
$response = $this->deleteJson('api/v1/links/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/links/1');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertEquals(0, Link::count());
|
||||
}
|
||||
|
||||
public function testDeleteRequestNotFound(): void
|
||||
{
|
||||
$response = $this->deleteJson('api/v1/links/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/links/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ class LinkCheckApiTest extends ApiTestCase
|
||||
'url' => 'https://example.com',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('api/v1/links/check?url=https://example.com', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/check?url=https://example.com');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'linksFound' => true,
|
||||
]);
|
||||
@ -38,9 +38,9 @@ class LinkCheckApiTest extends ApiTestCase
|
||||
'url' => 'https://test.com',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('api/v1/links/check?url=https://example.com', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/check?url=https://example.com');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'linksFound' => false,
|
||||
]);
|
||||
@ -48,9 +48,9 @@ class LinkCheckApiTest extends ApiTestCase
|
||||
|
||||
public function testCheckWithoutQuery(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/links/check', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/check');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'linksFound' => false,
|
||||
]);
|
||||
|
@ -21,9 +21,9 @@ class LinkNotesTest extends ApiTestCase
|
||||
'link_id' => $link->id,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('api/v1/links/1/notes', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1/notes');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['note' => $note->note],
|
||||
@ -33,11 +33,11 @@ class LinkNotesTest extends ApiTestCase
|
||||
|
||||
public function testLinksRequestWithoutLinks(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
factory(Link::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/links/1/notes', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1/notes');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [],
|
||||
]);
|
||||
@ -49,8 +49,8 @@ class LinkNotesTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/links/1/notes', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/links/1/notes');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace Tests\Controller\API;
|
||||
|
||||
use App\Models\LinkList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@ -23,9 +22,9 @@ class ListApiTest extends ApiTestCase
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/lists', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['name' => $list->name],
|
||||
@ -35,11 +34,11 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testMinimalCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/lists', [
|
||||
$response = $this->postJsonAuthorized('api/v1/lists', [
|
||||
'name' => 'Test List',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Test List',
|
||||
]);
|
||||
@ -51,14 +50,14 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testFullCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/lists', [
|
||||
$response = $this->postJsonAuthorized('api/v1/lists', [
|
||||
'name' => 'Test List',
|
||||
'description' => 'There could be a description here',
|
||||
'is_private' => false,
|
||||
'check_disabled' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Test List',
|
||||
]);
|
||||
@ -70,27 +69,28 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/lists', [
|
||||
$response = $this->postJsonAuthorized('api/v1/lists', [
|
||||
'name' => null,
|
||||
'description' => ['bla'],
|
||||
'is_private' => 'hello',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'name',
|
||||
'is_private',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'The name field is required.',
|
||||
'description' => 'The description must be a string.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testShowRequest(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/lists/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1');
|
||||
|
||||
$expectedLinkApiUrl = 'http://localhost/api/v1/lists/1/links';
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => $list->name,
|
||||
'links' => $expectedLinkApiUrl,
|
||||
@ -99,22 +99,22 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/lists/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testUpdateRequest(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/lists/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/lists/1', [
|
||||
'name' => 'Updated List Title',
|
||||
'description' => 'Custom Description',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Updated List Title',
|
||||
]);
|
||||
@ -126,34 +126,37 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidUpdateRequest(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/lists/1', [
|
||||
//
|
||||
], $this->generateHeaders());
|
||||
$response = $this->patchJsonAuthorized('api/v1/lists/1', [
|
||||
'name' => null,
|
||||
'description' => ['bla'],
|
||||
'is_private' => 'hello',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'name',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'The name field is required.',
|
||||
'description' => 'The description must be a string.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateRequestNotFound(): void
|
||||
{
|
||||
$response = $this->patchJson('api/v1/lists/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/lists/1', [
|
||||
'name' => 'Updated List Title',
|
||||
'description' => 'Custom Description',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testDeleteRequest(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->deleteJson('api/v1/lists/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/lists/1');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -162,8 +165,8 @@ class ListApiTest extends ApiTestCase
|
||||
|
||||
public function testDeleteRequestNotFound(): void
|
||||
{
|
||||
$response = $this->deleteJson('api/v1/lists/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/lists/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ class ListLinksTest extends ApiTestCase
|
||||
|
||||
$link->lists()->sync([$list->id]);
|
||||
|
||||
$response = $this->getJson('api/v1/lists/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1/links');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['url' => $link->url]
|
||||
@ -33,11 +33,11 @@ class ListLinksTest extends ApiTestCase
|
||||
|
||||
public function testLinksRequestWithoutLinks(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create();
|
||||
factory(LinkList::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/lists/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1/links');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => []
|
||||
]);
|
||||
@ -49,8 +49,8 @@ class ListLinksTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/lists/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1/links');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,8 @@ namespace Tests\Controller\API;
|
||||
|
||||
use App\Models\Link;
|
||||
use App\Models\Note;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NoteApiTest extends ApiTestCase
|
||||
{
|
||||
@ -18,12 +16,12 @@ class NoteApiTest extends ApiTestCase
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
|
||||
$response = $this->postJson('api/v1/notes', [
|
||||
$response = $this->postJsonAuthorized('api/v1/notes', [
|
||||
'link_id' => $link->id,
|
||||
'note' => 'Quae vero auctorem tractata ab fiducia dicuntur.',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'note' => 'Quae vero auctorem tractata ab fiducia dicuntur.',
|
||||
]);
|
||||
@ -37,13 +35,13 @@ class NoteApiTest extends ApiTestCase
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
|
||||
$response = $this->postJson('api/v1/notes', [
|
||||
$response = $this->postJsonAuthorized('api/v1/notes', [
|
||||
'link_id' => $link->id,
|
||||
'note' => 'Quae vero auctorem tractata ab fiducia dicuntur.',
|
||||
'is_private' => true,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'note' => 'Quae vero auctorem tractata ab fiducia dicuntur.',
|
||||
'is_private' => true,
|
||||
@ -56,32 +54,31 @@ class NoteApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/notes', [
|
||||
$response = $this->postJsonAuthorized('api/v1/notes', [
|
||||
'link_id' => null,
|
||||
'note' => null,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'link_id',
|
||||
'note',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'link_id' => 'The link id field is required.',
|
||||
'note' => 'The note field is required.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateRequest(): void
|
||||
{
|
||||
$link = factory(Link::class)->create();
|
||||
$note = factory(Note::class)->create([
|
||||
factory(Note::class)->create([
|
||||
'link_id' => $link->id,
|
||||
]);
|
||||
|
||||
$response = $this->patchJson('api/v1/notes/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/notes/1', [
|
||||
'link_id' => $link->id,
|
||||
'note' => 'Gallia est omnis divisa in partes tres, quarum.',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'note' => 'Gallia est omnis divisa in partes tres, quarum.',
|
||||
]);
|
||||
@ -93,45 +90,44 @@ class NoteApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidUpdateRequest(): void
|
||||
{
|
||||
$note = factory(Note::class)->create();
|
||||
factory(Note::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/notes/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/notes/1', [
|
||||
//
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'link_id',
|
||||
'note',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'link_id' => 'The link id field is required.',
|
||||
'note' => 'The note field is required.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateRequestNotFound(): void
|
||||
{
|
||||
$response = $this->patchJson('api/v1/notes/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/notes/1', [
|
||||
'link_id' => 1,
|
||||
'note' => 'Sed haec quis possit intrepidus aestimare tellus.',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testDeleteRequest(): void
|
||||
{
|
||||
$note = factory(Note::class)->create();
|
||||
factory(Note::class)->create();
|
||||
|
||||
$response = $this->deleteJson('api/v1/notes/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/notes/1', []);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertEquals(0, Note::count());
|
||||
}
|
||||
|
||||
public function testDeleteRequestNotFound(): void
|
||||
{
|
||||
$response = $this->deleteJson('api/v1/notes/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/notes/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ class SearchLinksTest extends ApiTestCase
|
||||
|
||||
public function testWithoutQuery(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/search/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/search/links');
|
||||
|
||||
$response->assertJsonValidationErrors([
|
||||
'query',
|
||||
'only_lists',
|
||||
'only_tags',
|
||||
'query' => 'A search query must be present if no lists or tags were provided.',
|
||||
'only_lists' => 'A list must be present if no query or some tags were provided.',
|
||||
'only_tags' => 'A tag must be present if no query or some lists were provided.',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -48,9 +48,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?query=%s', 'example');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'current_page' => 1,
|
||||
])
|
||||
@ -79,9 +79,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?query=%s&search_title=1', 'Test');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
@ -90,7 +90,7 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSearchByDescription()
|
||||
public function testSearchByDescription(): void
|
||||
{
|
||||
$link = factory(Link::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -106,9 +106,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?query=%s&search_description=1', 'Example');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
@ -117,7 +117,7 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSearchPrivateOnly()
|
||||
public function testSearchPrivateOnly(): void
|
||||
{
|
||||
$link = factory(Link::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -133,9 +133,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?query=%s&private_only=1', 'test');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
@ -144,7 +144,7 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSearchBrokenOnly()
|
||||
public function testSearchBrokenOnly(): void
|
||||
{
|
||||
$link = factory(Link::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -159,9 +159,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?query=%s&broken_only=1', 'test');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
@ -170,7 +170,7 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSearchWithLists()
|
||||
public function testSearchWithLists(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -191,9 +191,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?only_lists=%s', $list->id);
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
@ -202,7 +202,7 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSearchWithTags()
|
||||
public function testSearchWithTags(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -223,9 +223,9 @@ class SearchLinksTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/links?only_tags=%s', $tag->id);
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJsonFragment([
|
||||
'url' => $link->url,
|
||||
])
|
||||
|
@ -20,9 +20,9 @@ class SearchListsTest extends ApiTestCase
|
||||
|
||||
public function testWithoutQuery(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/search/lists', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/search/lists');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([]);
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ class SearchListsTest extends ApiTestCase
|
||||
'name' => 'Scientific Articles',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('api/v1/search/lists?query=', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/search/lists?query=');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([]);
|
||||
}
|
||||
|
||||
@ -59,9 +59,9 @@ class SearchListsTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/lists?query=%s', 'articles');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([
|
||||
$list->id => $list->name,
|
||||
$list2->id => $list2->name,
|
||||
@ -87,9 +87,9 @@ class SearchListsTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/lists?query=%s', 'ar');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([
|
||||
$list->id => $list->name,
|
||||
$list2->id => $list2->name,
|
||||
|
@ -20,9 +20,9 @@ class SearchTagsTest extends ApiTestCase
|
||||
|
||||
public function testWithoutQuery(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/search/tags', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/search/tags');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([]);
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ class SearchTagsTest extends ApiTestCase
|
||||
'name' => 'artificial-intelligence',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('api/v1/search/tags?query=', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/search/tags?query=');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([]);
|
||||
}
|
||||
|
||||
@ -64,9 +64,9 @@ class SearchTagsTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/tags?query=%s', 'programming');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([
|
||||
$tag->id => $tag->name,
|
||||
$tag2->id => $tag2->name,
|
||||
@ -93,9 +93,9 @@ class SearchTagsTest extends ApiTestCase
|
||||
]);
|
||||
|
||||
$url = sprintf('api/v1/search/tags?query=%s', 'p');
|
||||
$response = $this->getJson($url, $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized($url);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertExactJson([
|
||||
$tag->id => $tag->name,
|
||||
$tag2->id => $tag2->name,
|
||||
|
@ -3,10 +3,8 @@
|
||||
namespace Tests\Controller\API;
|
||||
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TagApiTest extends ApiTestCase
|
||||
{
|
||||
@ -24,9 +22,9 @@ class TagApiTest extends ApiTestCase
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/tags', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['name' => $tag->name],
|
||||
@ -36,11 +34,11 @@ class TagApiTest extends ApiTestCase
|
||||
|
||||
public function testMinimalCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/tags', [
|
||||
$response = $this->postJsonAuthorized('api/v1/tags', [
|
||||
'name' => 'Test Tag',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Test Tag',
|
||||
]);
|
||||
@ -52,12 +50,12 @@ class TagApiTest extends ApiTestCase
|
||||
|
||||
public function testFullCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/tags', [
|
||||
$response = $this->postJsonAuthorized('api/v1/tags', [
|
||||
'name' => 'Test Tag',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Test Tag',
|
||||
]);
|
||||
@ -69,25 +67,24 @@ class TagApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidCreateRequest(): void
|
||||
{
|
||||
$response = $this->postJson('api/v1/tags', [
|
||||
$response = $this->postJsonAuthorized('api/v1/tags', [
|
||||
'name' => null,
|
||||
'is_private' => 'hello',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'name',
|
||||
'is_private',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'The name field is required.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testShowRequest(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/tags/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags/1');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => $tag->name,
|
||||
]);
|
||||
@ -95,21 +92,21 @@ class TagApiTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/tags/1', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testUpdateRequest(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
factory(Tag::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/tags/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/tags/1', [
|
||||
'name' => 'Updated Tag Title',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'name' => 'Updated Tag Title',
|
||||
]);
|
||||
@ -121,43 +118,44 @@ class TagApiTest extends ApiTestCase
|
||||
|
||||
public function testInvalidUpdateRequest(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
factory(Tag::class)->create();
|
||||
|
||||
$response = $this->patchJson('api/v1/tags/1', [
|
||||
//
|
||||
], $this->generateHeaders());
|
||||
$response = $this->patchJsonAuthorized('api/v1/tags/1', [
|
||||
'name' => null,
|
||||
'is_private' => 'hello',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors([
|
||||
'name',
|
||||
]);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'The name field is required.',
|
||||
'is_private' => 'The is private field must be true or false.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateRequestNotFound(): void
|
||||
{
|
||||
$response = $this->patchJson('api/v1/tags/1', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/tags/1', [
|
||||
'name' => 'Updated Tag Title',
|
||||
'is_private' => false,
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function testDeleteRequest(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
factory(Tag::class)->create();
|
||||
|
||||
$response = $this->deleteJson('api/v1/tags/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/tags/1');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertEquals(0, Tag::count());
|
||||
}
|
||||
|
||||
public function testDeleteRequestNotFound(): void
|
||||
{
|
||||
$response = $this->deleteJson('api/v1/tags/1', [], $this->generateHeaders());
|
||||
$response = $this->deleteJsonAuthorized('api/v1/tags/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ class TagLinksTest extends ApiTestCase
|
||||
|
||||
$link->tags()->sync([$tag->id]);
|
||||
|
||||
$response = $this->getJson('api/v1/tags/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags/1/links');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['url' => $link->url],
|
||||
@ -33,11 +33,11 @@ class TagLinksTest extends ApiTestCase
|
||||
|
||||
public function testLinksRequestWithoutLinks(): void
|
||||
{
|
||||
$tag = factory(Tag::class)->create();
|
||||
factory(Tag::class)->create();
|
||||
|
||||
$response = $this->getJson('api/v1/tags/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags/1/links');
|
||||
|
||||
$response->assertStatus(200)
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'data' => [],
|
||||
]);
|
||||
@ -49,8 +49,8 @@ class TagLinksTest extends ApiTestCase
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/tags/1/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/tags/1/links');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class TrashApiTest extends ApiTestCase
|
||||
|
||||
public function testGetLinks(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/trash/links', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/trash/links');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -42,7 +42,7 @@ class TrashApiTest extends ApiTestCase
|
||||
|
||||
public function testGetLists(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/trash/lists', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/trash/lists');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -52,7 +52,7 @@ class TrashApiTest extends ApiTestCase
|
||||
|
||||
public function testGetTags(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/trash/tags', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/trash/tags');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -62,7 +62,7 @@ class TrashApiTest extends ApiTestCase
|
||||
|
||||
public function testGetNotes(): void
|
||||
{
|
||||
$response = $this->getJson('api/v1/trash/notes', $this->generateHeaders());
|
||||
$response = $this->getJsonAuthorized('api/v1/trash/notes');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -78,9 +78,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
'model' => 'links',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -91,9 +91,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
'model' => 'tags',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -104,9 +104,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
'model' => 'lists',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -117,9 +117,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
'model' => 'notes',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -130,9 +130,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
//'model' => 'links',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertJsonValidationErrors([
|
||||
'model' => 'The model field is required.',
|
||||
@ -143,9 +143,9 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->deleteJson('api/v1/trash/clear', [
|
||||
$response = $this->deleteJsonAuthorized('api/v1/trash/clear', [
|
||||
'model' => 'shoes',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertJsonValidationErrors([
|
||||
'model' => 'The selected model is invalid.',
|
||||
@ -160,10 +160,10 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
'model' => 'link',
|
||||
'id' => '1',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -174,10 +174,10 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
'model' => 'tag',
|
||||
'id' => '1',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -188,10 +188,10 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
'model' => 'list',
|
||||
'id' => '1',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -202,10 +202,10 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
'model' => 'note',
|
||||
'id' => '1',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
@ -216,14 +216,14 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
//'model' => 'link',
|
||||
//'id' => '1',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertJsonValidationErrors([
|
||||
'model',
|
||||
'id',
|
||||
'model' => 'The model field is required.',
|
||||
'id' => 'The id field is required.',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -231,10 +231,10 @@ class TrashApiTest extends ApiTestCase
|
||||
{
|
||||
$this->setupTrashTestData();
|
||||
|
||||
$response = $this->patchJson('api/v1/trash/restore', [
|
||||
$response = $this->patchJsonAuthorized('api/v1/trash/restore', [
|
||||
'model' => 'link',
|
||||
'id' => '1345235',
|
||||
], $this->generateHeaders());
|
||||
]);
|
||||
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user