<commit_before><?php

namespace Tests\Feature;

use Coyote\Coupon;
use Coyote\Firm;
use Coyote\Job;
use Coyote\User;
use Faker\Factory;
use Tests\TestCase;

class JobApiTest extends TestCase
{
    private $user;
    private $token;
    private $faker;

    public function setUp()
    {
        parent::setUp();

        $this->user = factory(User::class)->create();
        $this->token = $this->user->createToken('<PASSWORD>')->accessToken;

        $this->faker = Factory::create();
    }

    public function testSubmitSuccessful()
    {
        $coupon = Coupon::create(['amount' => 30, 'code' => str_random(), 'user_id' => $this->user->id]);

        $data = [
            'title' => $this->faker->text(60),
            'salary_from' => 3000,
            'salary_to' => 5000,
            'rate' => 'weekly',
            'currency' => 'USD',
            'plan' => 'standard',
            'seniority' => 'lead',
            'employment' => 'mandatory',
            'recruitment' => $this->faker->url,
            'locations' => [
                [
                    'city' => 'Wrocław',
                    'street' => 'Rynek',
                    'street_number' => '23',
                    'country' => 'PL'
                ]
            ]
        ];

        $response = $this->json('POST', '/v1/jobs', $data, ['Authorization' => 'Bearer ' . $this->token, 'Accept' => 'application/json']);

        $this->assertEquals(201, $response->getStatusCode());
        $response->assertJsonFragment([
            'title' => $data['title'],
            'currency' => $data['currency'],
            'salary_from' => $data['salary_from'],
            'salary_to' => $data['salary_to'],
            'rate' => $data['rate'],
            'employment' => $data['employment'],
            'seniority' => $data['seniority'],
            'is_gross' => false,
            'is_remote' => false,
            'firm' => null
        ]);

        $this->assertNotNull(Coupon::withTrashed()->find($coupon->id)->deleted_at);

        $result = json_decode($response->getContent(), true);
        /** @var Job $job */
        $job = Job::find($result['id']);

        $this->assertFalse($job->enable_apply);
        $this->assertEquals($job->seniority, $data['seniority']);
        $this->assertEquals($job->employment, $data['employment']);
        $this->assertEquals($job->rate, $data['rate']);

    }

    public function testSubmitWithAlreadyCreatedFirm()
    {
        Coupon::create(['amount' => 57, 'code' => str_random(), 'user_id' => $this->user->id]);
        $firm = factory(Firm::class)->create(['user_id' => $this->user->id]);<commit_msg>dodatkowy test zapisu oferty wraz z firma<commit_after><?php

namespace Tests\Feature;

use Coyote\Coupon;
use Coyote\Firm;
use Coyote\Job;
use Coyote\User;
use Faker\Factory;
use Tests\TestCase;

class JobApiTest extends TestCase
{
    private $user;
    private $token;
    private $faker;

    public function setUp()
    {
        parent::setUp();

        $this->user = factory(User::class)->create();
        $this->token = $this->user->createToken('4programmers.net')->accessToken;

        $this->faker = Factory::create();
    }

    public function testSubmitSuccessful()
    {
        $coupon = Coupon::create(['amount' => 30, 'code' => str_random(), 'user_id' => $this->user->id]);

        $data = [
            'title' => $this->faker->text(60),
            'salary_from' => 3000,
            'salary_to' => 5000,
            'rate' => 'weekly',
            'currency' => 'USD',
            'plan' => 'standard',
            'seniority' => 'lead',
            'employment' => 'mandatory',
            'recruitment' => $this->faker->url,
            'is_gross' => true,
            'locations' => [
                [
                    'city' => 'Wrocław',
                    'street' => 'Rynek',
                    'street_number' => '23',
                    'country' => 'PL'
                ]
            ]
        ];

        $response = $this->json('POST', '/v1/jobs', $data, ['Authorization' => 'Bearer ' . $this->token, 'Accept' => 'application/json']);

        $this->assertEquals(201, $response->getStatusCode());
        $response->assertJsonFragment([
            'title' => $data['title'],
            'currency' => $data['currency'],
            'salary_from' => $data['salary_from'],
            'salary_to' => $data['salary_to'],
            'rate' => $data['rate'],
            'employment' => $data['employment'],
            'seniority' => $data['seniority'],
            'is_gross' => true,
            'is_remote' => false,
            'firm' => null
        ]);

        $this->assertNotNull(Coupon::withTrashed()->find($coupon->id)->deleted_at);

        $result = json_decode($response->getContent(), true);
        /** @var Job $job */
        $job = Job::find($result['id']);

        $this->assertFalse($job->enable_apply);
        $this->assertEquals($job->seniority, $data['seniority']);
        $this->assertEquals($job->employment, $data['employment']);
        $this->assertEquals($job->rate, $data['rate']);

    }

    public function testSubmitWithFirm()
    {
        $coupon = Coupon::create(['amount' => 30, 'code' => str_random(), 'user_id' => $this->user->id]);

        $data = [
            'title' => $this->faker->text(60),
            'plan' => 'standard',
            'firm' => [
                'name' => $this->faker->company
            ]
        ];

        $response = $this->json('POST', '/v1/jobs', $data, ['Authorization' => 'Bearer ' . $this->token, 'Accept' => 'application/json']);
        $this->assertEquals(201, $response->getStatusCode());

        $response->assertJsonFragment([
            'title' => $data['title'],
            'currency' => 'PLN',
            'salary_from' => null,
            'salary_to' => null,
            'rate' => 'monthly',
            'employment' => 'employment',
            'seniority' => null,
            'is_gross' => false,
            'is_remote' => false
        ]);
    }

    public function testSubmitWithAlreadyCreatedFirm()
    {
        Coupon::create(['amount' => 57, 'code' => str_random(), 'user_id' => $this->user->id]);
        $firm = factory(Firm::class)->create(['user_id' => $this->user->id]);
{'fraction_non_alphanumeric': 0.19453761379971252, 'fraction_numerical': 0.00782622584251717, 'mean_word_length': 2.096933728981207, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 172, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2986180', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1883, 'n_words': 321}