<?php

use App\EmailTemplate;
class TemplateTest extends TestCase
{
    /**
     * Test to check get templates
     *
     * @return void
     */
    public function testTemplate()
    {
       $response = $this->call('GET', 'api/v1/template/');
       $this->assertEquals(200, $response->status());
    }
    
    /**
     * Test to check save template
     *
     * @return void
     */
    public function testSaveTemplate()
    {
       $slug = str_random(20); 
       $this->post('api/v1/template', ['info' => 'asdfg', 'subject' => 'sample', 'status'=>'1', 'description' => 'dsd', 'slug' => $slug])
             ->seeJson([
                'status' => 'success',
             ]);
       
       $response = $this->call('POST', 'api/v1/template', ['info' => 'asdfg', 'subject' => 'sample', 'status'=>'1', 'description' => 'dsd', 'slug' => 'info2']);
       $this->assertNotEquals(200, $response->status());
       
    }
    
     /**
     * Test to check get templates
     *
     * @return void
     */
    public function testGetTemplate()
    {
       $last = EmailTemplate::max('id'); 
       $response = $this->call('GET', "api/v1/template/$last");
       $this->assertEquals(200, $response->status());
       
       $this->get('api/v1/template/000')
             ->seeJson([
                'status' => 'fail',
             ]);
    }
    
    /**
     * Test to check update template
     *
     * @return void
     */
    public function testUpdateTemplate()
    {
       $last = EmailTemplate::max('id');  
       $slug = str_random(20); 
       $this->put("api/v1/template/$last", ['info' => 'asdfg', 'subject' => 'sample', 'status'=>'1', 'description' => 'dsd', 'slug' => $slug])
             ->seeJson([
                'status' => 'success',
             ]);
       
       $this->put('api/v1/template/112121', ['info' => 'asdfg', 'subject' => 'sample', 'status'=>'1', 'description' => 'dsd', 'slug' => $slug])
             ->seeJson([
                'status' => 'fail',
             ]);
    }
    
    
    /**
     * Test to check change status
     *
     * @return void
     */
    public function testChangeTemplateStatus()
    {
       $last = EmailTemplate::max('id');   
       $this->put('api/v1/template', ['id' => $last, 'status' => 1])
             ->seeJson([
                'status' => 'success',
             ]);
       
       $this->put('api/v1/template', ['id' => 0000, 'status' => 1])
             ->seeJson([
                'status' => 'fail',
             ]);
    }
    
    
}
