<commit_before><?php

namespace Tests\Feature\Api;

use App\FileAlias;
use App\ProxyFile;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\JsonApiRequestModelConcern;
use Tests\TestCase;

class AliasesResourceTest extends TestCase
{
    use DatabaseMigrations, DatabaseTransactions, JsonApiRequestModelConcern;

    /** @test */
    public function it_can_store_a_new_alias_by_api()
    {
        // ARRANGE
        /** @var ProxyFile $proxyFile */
        $proxyFile = factory(ProxyFile::class)->create();

        /** @var FileAlias $alias */
        $alias = factory(FileAlias::class, 'request')->make();

        // ACT
        $response = $this->postJson(
            '/api/files/' . $proxyFile->reference . '/aliases',
            $this->createRequestModel('aliases', $alias->toArray())
        );

        // ASSERT
        $response->assertStatus(204);
    }

}<commit_msg>fetch alias resource via api tested<commit_after><?php

namespace Tests\Feature\Api;

use App\FileAlias;
use App\ProxyFile;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\JsonApiRequestModelConcern;
use Tests\TestCase;

class AliasesResourceTest extends TestCase
{
    use DatabaseMigrations, DatabaseTransactions, JsonApiRequestModelConcern;

    /** @test */
    public function it_can_store_a_new_alias_by_api()
    {
        // ARRANGE
        /** @var ProxyFile $proxyFile */
        $proxyFile = factory(ProxyFile::class)->create();

        /** @var FileAlias $alias */
        $alias = factory(FileAlias::class, 'request')->make();

        // ACT
        $response = $this->postJson(
            '/api/files/' . $proxyFile->reference . '/aliases',
            $this->createRequestModel('aliases', $alias->toArray())
        );

        // ASSERT
        $response->assertStatus(204);
    }

    /** @test */
    public function it_can_retrieve_an_alias_resource_by_api()
    {
        // ARRANGE
        /** @var ProxyFile $proxyFile */
        $proxyFile = factory(ProxyFile::class)->create();

        /** @var FileAlias $alias */
        $alias = factory(FileAlias::class)->create([
            'proxy_file_id' => $proxyFile->id,
        ]);

        // ACT
        $response = $this->getJson('/api/aliases/' . $proxyFile->reference . '.' . $alias->getKey());

        // ASSERT
        $response->assertStatus(200)
            ->assertExactJson([
                'data' => [
                    'type' => 'aliases',
                    'id' => $proxyFile->reference . '.' . $alias->getKey(),
                    'attributes' => [
                        'path' => $alias->path,
                        'valid_from' => $alias->valid_from->toIso8601String(),
                        'valid_until' => null,
                        'hits' => 0,
                        'hits_left' => null,
                        'hits_total' => null
                    ],
                    'links' => [
                        'download' => 'http://localhost/' . $alias->path,
                        'self' => 'http://localhost/api/aliases/' . $proxyFile->reference . '.' . $alias->getKey()
                    ]
                ]
            ]);
    }

}
{'fraction_non_alphanumeric': 0.14490543014032947, 'fraction_numerical': 0.004270896888346553, 'mean_word_length': 1.956717763751127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678214', 'n_tokens_mistral': 932, 'n_tokens_neox': 906, 'n_words': 155}