mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-26 23:18:37 +03:00
Created API test for Domain redirects
This commit is contained in:
parent
40a7d5a112
commit
de81e81ecb
1 changed files with 100 additions and 0 deletions
100
module/Rest/test-api/Action/DomainRedirectsTest.php
Normal file
100
module/Rest/test-api/Action/DomainRedirectsTest.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class DomainRedirectsTest extends ApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function anErrorIsReturnedWhenTryingToEditDefaultDomain(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/domains/redirects', [
|
||||
RequestOptions::JSON => ['domain' => 'doma.in'],
|
||||
]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(self::STATUS_FORBIDDEN, $resp->getStatusCode());
|
||||
self::assertEquals(self::STATUS_FORBIDDEN, $payload['status']);
|
||||
self::assertEquals('INVALID_DOMAIN', $payload['type']);
|
||||
self::assertEquals(
|
||||
'You cannot configure default domain\'s redirects this way. Use the configuration or env vars.',
|
||||
$payload['detail'],
|
||||
);
|
||||
self::assertEquals('Invalid domain', $payload['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideInvalidDomains
|
||||
*/
|
||||
public function anErrorIsReturnedWhenTryingToEditAnInvalidDomain(array $request): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/domains/redirects', [
|
||||
RequestOptions::JSON => $request,
|
||||
]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
||||
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
||||
self::assertEquals('INVALID_ARGUMENT', $payload['type']);
|
||||
self::assertEquals('Provided data is not valid', $payload['detail']);
|
||||
self::assertEquals('Invalid data', $payload['title']);
|
||||
}
|
||||
|
||||
public function provideInvalidDomains(): iterable
|
||||
{
|
||||
yield 'no domain' => [[]];
|
||||
yield 'empty domain' => [['domain' => '']];
|
||||
yield 'null domain' => [['domain' => null]];
|
||||
yield 'invalid domain' => [['domain' => '192.168.1.1']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideRequests
|
||||
*/
|
||||
public function allowsToEditDomainRedirects(array $request, array $expectedResponse): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/domains/redirects', [
|
||||
RequestOptions::JSON => $request,
|
||||
]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(self::STATUS_OK, $resp->getStatusCode());
|
||||
self::assertEquals($expectedResponse, $payload);
|
||||
}
|
||||
|
||||
public function provideRequests(): iterable
|
||||
{
|
||||
yield 'new domain' => [[
|
||||
'domain' => 'my-new-domain.com',
|
||||
'regular404Redirect' => 'foo.com',
|
||||
], [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => 'foo.com',
|
||||
'invalidShortUrlRedirect' => null,
|
||||
]];
|
||||
yield 'existing domain with redirects' => [[
|
||||
'domain' => 'detached-with-redirects.com',
|
||||
'baseUrlRedirect' => null,
|
||||
'invalidShortUrlRedirect' => 'foo.com',
|
||||
], [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => 'bar.com',
|
||||
'invalidShortUrlRedirect' => 'foo.com',
|
||||
]];
|
||||
yield 'existing domain with no redirects' => [[
|
||||
'domain' => 'example.com',
|
||||
'baseUrlRedirect' => null,
|
||||
'invalidShortUrlRedirect' => 'foo.com',
|
||||
], [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => 'foo.com',
|
||||
]];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue