<?php

namespace Tests\Api;

use Tests\ApiTestTrait;
use Tests\TestCase;
use Tests\Traits\MakeCurrencyRateTrait;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class CurrencyRateApiTest extends TestCase
{
    use MakeCurrencyRateTrait, ApiTestTrait, WithoutMiddleware, DatabaseTransactions;

    /**
     * @test
     */
    public function testCreateCurrencyRate()
    {
        $currencyRate = $this->fakeCurrencyRateData();
        $this->json('POST', '/api/v1/currency-rates', $currencyRate);

        $this->assertApiResponse($currencyRate);
    }

    /**
     * @test
     */
    public function testReadCurrencyRate()
    {
        $currencyRate = $this->makeCurrencyRate();
        $this->json('GET', '/api/v1/currency-rates/'.$currencyRate->id);

        $this->assertApiResponse($currencyRate->toArray());
    }

    /**
     * @test
     */
    public function testUpdateCurrencyRate()
    {
        $currencyRate = $this->makeCurrencyRate();
        $editedCurrencyRate = $this->fakeCurrencyRateData();

        $this->json('PUT', '/api/v1/currency-rates/'.$currencyRate->id, $editedCurrencyRate);

        $this->assertApiResponse($editedCurrencyRate);
    }

    /**
     * @test
     */
    public function testDeleteCurrencyRate()
    {
        $currencyRate = $this->makeCurrencyRate();
        $this->json('DELETE', '/api/v1/currency-rates/'.$currencyRate->id);

        $this->assertApiSuccess();
        $this->json('GET', '/api/v1/currency-rates/'.$currencyRate->id);

        $this->assertResponseStatus(404);
    }
}
