Completed
Pull Request — master (#554)
by Alejandro
11:37 queued 08:50
created

unprocessableEntityIsReturnedWhenTryingToDeleteUrlWithTooManyVisits()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioApiTest\Shlink\Rest\Action;
6
7
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
8
9
class DeleteShortUrlActionTest extends ApiTestCase
10
{
11
    /** @test */
12
    public function notFoundErrorIsReturnWhenDeletingInvalidUrl(): void
13
    {
14
        $expectedDetail = 'No URL found with short code "invalid"';
15
16
        $resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid');
17
        $payload = $this->getJsonResponsePayload($resp);
18
19
        $this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
20
        $this->assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
21
        $this->assertEquals('INVALID_SHORTCODE', $payload['type']);
22
        $this->assertEquals('INVALID_SHORTCODE', $payload['error']); // Deprecated
23
        $this->assertEquals($expectedDetail, $payload['detail']);
24
        $this->assertEquals($expectedDetail, $payload['message']); // Deprecated
25
        $this->assertEquals('Short URL not found', $payload['title']);
26
        $this->assertEquals('invalid', $payload['shortCode']);
27
    }
28
29
    /** @test */
30
    public function unprocessableEntityIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void
31
    {
32
        // Generate visits first
33
        for ($i = 0; $i < 20; $i++) {
34
            $this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
35
        }
36
        $expectedDetail = 'Impossible to delete short URL with short code "abc123" since it has more than "15" visits.';
37
38
        $resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
39
        $payload = $this->getJsonResponsePayload($resp);
40
41
        $this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $resp->getStatusCode());
42
        $this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $payload['status']);
43
        $this->assertEquals('INVALID_SHORTCODE_DELETION', $payload['type']);
44
        $this->assertEquals('INVALID_SHORTCODE_DELETION', $payload['error']); // Deprecated
45
        $this->assertEquals($expectedDetail, $payload['detail']);
46
        $this->assertEquals($expectedDetail, $payload['message']); // Deprecated
47
        $this->assertEquals('Cannot delete short URL', $payload['title']);
48
    }
49
}
50