<?php
class KIPTest extends BaseTest
{
    // public function testSummaryJenjangShouldGiveSuccessResponse() {
    //     $response = $this->client->request('GET', 'kip/summary_jenjang');

    //     $statusCode = $response->getStatusCode();
    //     $jsonResponse = json_decode($response->getBody(), TRUE);
    //     $this->assertEquals(200, $statusCode);
    //     $this->assertArraySubset(
    //         [
    //             'success' => true
    //         ],
    //         $jsonResponse,
    //         "Error on kip/jenjang_summary"
    //     );
    //     $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
    //     self::$messages = array_merge(self::$messages, ["\n\t\t\tkip/jenjang_summary Passed"]);
    // }

    // public function testSummaryNasionalShouldGiveSuccessResponse() {
    //     $response = $this->client->request('GET', 'kip/summary_nasional',
    //         [
    //             'query' => [
    //                 'jenjang' => '1'
    //             ]
    //         ]
    //     );

    //     $statusCode = $response->getStatusCode();
    //     $jsonResponse = json_decode($response->getBody(), TRUE);
    //     $this->assertEquals(200, $statusCode);
    //     $this->assertContains(
    //         [
    //             'success' => true
    //         ],
    //         $jsonResponse,
    //         "Error on kip/summary_nasional"
    //     );
    //     $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
    //     self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_nasional Passed"]);
    // }

    public function testSummaryNasionalShouldGiveNotFoundResponse() {
        $response = $this->client->request('GET', 'kip/summary_nasional',
            [
                'query' => [
                    'jenjang' => '90'
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/summary_nasional"
        );
        $this->assertEquals(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_nasional not found response Passed"]);
    }

    public function testSummaryNasionalShouldGiveRequiredResponse() {
        try {
            $response = $this->client->request('GET', 'kip/summary_nasional');
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();

            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "jenjang",
                            "message" => "Field jenjang is required"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/summary_nasional"
            );


            self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_nasional required response Passed"]);
        }

    }

    // public function testSummaryProvinsiShouldGiveSuccessResponse() {
    //     $response = $this->client->request('GET', 'kip/summary_provinsi',
    //         [
    //             'query' => [
    //                 'jenjang' => 3,
    //                 'provinsi' => '31'
    //             ]
    //         ]
    //     );

    //     $statusCode = $response->getStatusCode();
    //     $jsonResponse = json_decode($response->getBody(), TRUE);
    //     $this->assertEquals(200, $statusCode);
    //     $this->assertContains(
    //         [
    //             'success' => true
    //         ],
    //         $jsonResponse,
    //         "Error on kip/summary_provinsi"
    //     );
    //     $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
    //     self::$messages = array_merge(self::$messages, ["\n\t\t\tkip/summary_provinsi Passed"]);
    // }

    public function testSummaryProvinsiShouldGiveNotFoundResponse() {
        $response = $this->client->request('GET', 'kip/summary_provinsi',
            [
                'query' => [
                    'jenjang' => 90,
                    'provinsi' => '01'
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/summary_provinsi"
        );
        $this->assertEquals(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_nasional not found response Passed"]);
    }

    public function testSummaryProvinsiShouldGiveRequiredResponse() {
        try {
            $response = $this->client->request('GET', 'kip/summary_provinsi');
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();

            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "jenjang",
                            "message" => "Field jenjang is required"
                        ],
                        [
                            "field" => "provinsi",
                            "message" => "Field provinsi is required"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/summary_provinsi"
            );


            self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_provinsi required response Passed"]);
        }

    }

    // public function testSummaryKotaShouldGiveSuccessResponse() {
    //     $response = $this->client->request('GET', 'kip/summary_kota_kabupaten',
    //         [
    //             'query' => [
    //                 'jenjang' => 1,
    //                 'kota_kabupaten' => '1305',
    //                 'limit' => 10,
    //                 'offset' => 0
    //             ]
    //         ]
    //     );

    //     $statusCode = $response->getStatusCode();
    //     $jsonResponse = json_decode($response->getBody(), TRUE);
    //     $this->assertEquals(200, $statusCode);
    //     $this->assertContains(
    //         [
    //             'success' => true
    //         ],
    //         $jsonResponse,
    //         "Error on kip/summary_kota_kabupaten"
    //     );
    //     $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
    //     self::$messages = array_merge(self::$messages, ["\n\t\t\tkip/summary_kota_kabupaten Passed"]);
    // }

    public function testSummaryKotaShouldGiveNotFoundResponse() {
        $response = $this->client->request('GET', 'kip/summary_kota_kabupaten',
            [
                'query' => [
                    'jenjang' => 90,
                    'kota_kabupaten' => '3101',
                    'limit' => 10,
                    'offset' => 0
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/summary_kota_kabupaten"
        );
        $this->assertEquals(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_kota_kabupaten not found response Passed"]);
    }

    public function testSummaryKotaShouldGiveRequiredResponse() {
        try {
            $response = $this->client->request('GET', 'kip/summary_kota_kabupaten');
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();

            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "jenjang",
                            "message" => "Field jenjang is required"
                        ],
                        [
                            "field" => "kota_kabupaten",
                            "message" => "Field kota_kabupaten is required"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/summary_kota_kabupaten"
            );


            self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_kota_kabupaten required response Passed"]);
        }

    }

    public function testSummaryKotaShouldGiveMustBeNumericResponse() {
        try{
            $response = $this->client->request('GET', 'kip/summary_kota_kabupaten',
                [
                    'query' => [
                        'jenjang' => 90,
                        'kota_kabupaten' => '3101',
                        'limit' => 'a',
                        'offset' => 'b'
                    ]
                ]
            );
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "limit",
                            "message" => "Field limit must be numeric"
                        ],
                        [
                            "field" => "offset",
                            "message" => "Field offset must be numeric"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/summary_kota_kabupaten"
            );
            self::$messages = array_merge(self::$messages, ["\t\t\tkip/summary_kota_kabupaten must be numeric response Passed"]);
        }
    }

    public function testSekolahDetailShouldGiveSuccessResponse() {
        $response = $this->client->request('GET', 'kip/sekolah_detail',
            [
                'query' => [
                    "npsn" => "10307050"
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/sekolah_detail"
        );
        $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\n\t\t\tkip/sekolah_detail Passed"]);
    }

    public function testSekolahDetailShouldGiveNotFoundResponse() {
        $response = $this->client->request('GET', 'kip/sekolah_detail',
            [
                'query' => [
                    "npsn" => "abc"
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/sekolah_detail"
        );
        $this->assertEquals(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\t\t\tkip/sekolah_detail not found response Passed"]);
    }

    public function testSekolahDetailShouldGiveRequiredResponse() {
        try {
            $response = $this->client->request('GET', 'kip/sekolah_detail');
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();

            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "npsn",
                            "message" => "Field npsn is required"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/sekolah_detail"
            );


            self::$messages = array_merge(self::$messages, ["\t\t\tkip/sekolah_detail required response Passed"]);
        }

    }

    public function testDetailShouldGiveSuccessResponse() {
        $response = $this->client->request('GET', 'kip/detail',
            [
                'query' => [
                    "nisn" => "0068758550"
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/detail"
        );
        $this->assertGreaterThan(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\n\t\t\tkip/detail Passed"]);
    }

    public function testDetailShouldGiveNotFoundResponse() {
        $response = $this->client->request('GET', 'kip/detail',
            [
                'query' => [
                    "nisn" => "abc"
                ]
            ]
        );

        $statusCode = $response->getStatusCode();
        $jsonResponse = json_decode($response->getBody(), TRUE);
        $this->assertEquals(200, $statusCode);
        $this->assertContains(
            [
                'success' => true
            ],
            $jsonResponse,
            "Error on kip/detail"
        );
        $this->assertEquals(0, $jsonResponse['data']['total_record']);
        self::$messages = array_merge(self::$messages, ["\t\t\tkip/detail not found response Passed"]);
    }

    public function testDetailShouldGiveRequiredResponse() {
        try {
            $response = $this->client->request('GET', 'kip/detail');
        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();

            $statusCode = $response->getStatusCode();
            $jsonResponse = json_decode($response->getBody(), TRUE);
            $this->assertEquals(460, $statusCode);
            $this->assertArraySubset(
                [
                    'success' => false,
                    "errors" => [
                        [
                            "field" => "nisn",
                            "message" => "Field nisn is required"
                        ]
                    ]
                ],
                $jsonResponse,
                "Error on kip/detail"
            );


            self::$messages = array_merge(self::$messages, ["\t\t\tkip/detail required response Passed"]);
        }

    }
}
?>