<commit_before><?php

namespace Tests;

use App\User;
use App\Company;
use App\Role;

use TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class UserRolesCompanyTest extends TestCase
{

    use DatabaseTransactions;

    /*
    - everyone can see user details
    - owner can CRUD user
    - ADMIN: can  perform all action in the account. Also create
             new users with different level of access
    - MANAGER: can perform all action in the account, except insert
             and suspend a company.
    - VIEWER: can view. 
    */

    public function test_every_user_role_can_see_any_company_details()
    {
        // create owner with company
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $roles = Role::getAllRoles();

        foreach($roles as $role) {
            $user = factory(User::class, $role)->create();
            $this->actingAs($user)
                 ->get('/company/'.$company->id)
                 ->assertResponseStatus(200);    
        }
    }

    public function test_admin_should_see_edit_company_button()
    {
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $user = factory(User::class, 'admin')->create();
        
        $this->actingAs($user)
             ->visit('/companies')
             ->see($company->name)
             ->see('edit-company-'.$company->id);
    }

    public function test_admin_can_create_company()
    {
        $user = factory(User::class, 'admin')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->dontSee('User is not authorised to Create Company.')
             ->see('Add Company');
    }

    public function test_admin_can_delete_company()
    {
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $user = factory(User::class, 'admin')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->see('Delete')
             ->see('delete-company-'.$company->id);
    }


}<commit_msg>Add test Manager cannot create and can delete Company<commit_after><?php

namespace Test;

use App\User;
use App\Company;
use App\Role;

use TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class UserRolesCompanyTest extends TestCase
{

    use DatabaseTransactions;

    /*
    - everyone can see user details
    - owner can CRUD user
    - ADMIN: can  perform all action in the account. Also create
             new users with different level of access
    - MANAGER: can perform all action in the account, except insert
             and suspend a company.
    - VIEWER: can view. 
    */

    public function test_every_user_role_can_see_any_company_details()
    {
        // create owner with company
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $roles = Role::getAllRoles();

        foreach($roles as $role) {
            $user = factory(User::class, $role)->create();
            $this->actingAs($user)
                 ->get('/company/'.$company->id)
                 ->assertResponseStatus(200);    
        }
    }

    public function test_admin_should_see_edit_company_button()
    {
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $user = factory(User::class, 'admin')->create();
        
        $this->actingAs($user)
             ->visit('/companies')
             ->see($company->name)
             ->see('edit-company-'.$company->id);
    }

    public function test_admin_can_create_company()
    {
        $user = factory(User::class, 'admin')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->dontSee('User is not authorised to Create Company.')
             ->see('Add Company');
    }

    public function test_admin_can_delete_company()
    {
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $user = factory(User::class, 'admin')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->see('Delete')
             ->see('delete-company-'.$company->id);
    }

    public function test_manager_cannot_create_company()
    {
        $user = factory(User::class, 'manager')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->see('User is not authorised to Create Company.')
             ->dontSee('Add Company');
    }


    public function test_manager_can_delete_company()
    {
        $owner = factory(User::class, 'owner')->create();
        $owner->companies()->save($company = factory(Company::class)->create());

        $user = factory(User::class, 'manager')->create();
        $this->actingAs($user)
             ->visit('/companies')
             ->see('delete-company-'.$company->id);
    }


}
{'fraction_non_alphanumeric': 0.15051584377302873, 'fraction_numerical': 0.001105379513633014, 'mean_word_length': 2.4690095846645366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, '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': '3373234', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1483, 'n_words': 312}