<?php

require_once 'ABaseTest.php';

class StranasReportTest extends BaseTest
{
    protected $token;
    protected $userId;

    public function setUp()
    {
        parent::setUp();
        $loginInfo = $this->doLogin();
        $this->token = $loginInfo['token'];
        $this->userId = $loginInfo['user_id'];
    }

    public function doLogin()
    {
        $login = $this->login(getenv("TEST_ADMIN_USERNAME"), getenv("TEST_ADMIN_PASSWORD"));
        $this->assertContains(
            [
                'success' => true
            ],
            $login,
            "StranasReportTest:login Failed"
        );
        return $login['data'];
    }

    public function testIndexSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "\ntestIndexSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testTop10Success()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/top10',
            200,
            [
                'success' => true,
                'data' => [
                    'top10' => []
                ]
            ],
            "testTop10Success Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testGetBobotSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/getBobot',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testGetBobotSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testGenAchievmentSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/genAchievement',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testGenAchievmentSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testLogSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/log?id_instansi=1&id_target=1',
            200,
            [
                'success' => true,
                'data' => [
                    'hierarchy' => [],
                    'result' => []
                ]
            ],
            "testLogSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testTargetSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/target?id_instansi=1&id_target=1',
            200,
            [
                'success' => true,
                'data' => [
                    'hierarchy' => [],
                    'result' => []
                ]
            ],
            "testTargetSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testDashboardSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/dashboard?type=instansi',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testDashboardSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testGenDashboardSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/genDashboard',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testGenDashboardSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testGenExcelSuccess()
    {
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/genExcel',
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testGenExcelSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }

    public function testGenNewPeriodSuccess()
    {
        // stranas_periode.id yang aktif saat ini
        $periode = 8;
        $this->doAPIShouldGiveSubsetResponse(
            'GET',
            'stranas/report/genNewPeriod?periode=' . $periode,
            200,
            [
                'success' => true,
                'data' => [
                    'result' => []
                ]
            ],
            "testGenNewPeriodSuccess Passed",
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . $this->token
                ]
            ]
        );
    }
}