<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;

class IndexControllerTest extends TestCase
{
    use RefreshDatabase;

    protected $adminToken;

    public function setUp(): void
    {
        parent::setUp();
        Role::create(['name' => 'Admin']);
        $admin = factory(User::class)->create();
        $admin->assignRole('Admin');
        $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->registerPermissions();
        $this->adminToken = \JWTAuth::fromUser($admin);
    }

    public function testGETVue()
    {
        $menuItems = [
            [
                'name' => 'strings.dashboard',
                'icon' => 'grid-outline',
                'link' => '/dashboard',
                'permissions' => [
                    'dashboard.index'
                ],
            ],
            [
                'name' => 'strings.customers',
                'icon' => 'people-outline',
                'link' => '/customers',
                'permissions' => [
                    'customers.index'
                ],
            ],
            [
                'name' => 'strings.users',
                'icon' => 'people-outline',
                'link' => '/users',
                'permissions' => [
                    'users.index'
                ],
            ],
            [
                'name' => 'strings.purchase_orders',
                'icon' => 'file-text-outline',
                'link' => '/purchase-orders',
                'permissions' => [
                    'purchase_orders.index'
                ],
            ],
        ];

        $response = $this->withHeaders([
                'Authorization' => 'Bearer '.$this->adminToken,
            ])
            ->json(
                'GET',
                '/api/vue'
            )
            ->assertStatus(200)
            ->assertHeader('Content-Type', 'application/json')
            ->assertJson([
                'menuItems' => [],
                'notifications' => []
            ]);
    }
}
