Done!

Druid Application Test



namespace App\Tests\Application\Analytics\Brand\Explode;

use App\Tests\Integration\Controller\DruidTestCase;

class AnalyticsInitiatorInsightsMetricsConversionExplodeTest extends DruidTestCase
{
    public function testInitiatorInsightsMetricsIsExecutedAsPartOfMainQuery(): void
    {
        $sql = 'SELECT device_id AS "device_id", LOOKUP(device_id, \'device_name\') AS "device_name", COUNT(DISTINCT(conversion_id)) AS "total_conversions", SUM(sum_row_count) AS "initiator_total_conversion_items" FROM conversion_item WHERE (campaign_id = ?) AND (__time BETWEEN ? AND ?) GROUP BY 1 LIMIT 10000';

        $params = [
            'parameters' => [
                [
                    'type' => 'VARCHAR',
                    'value' => '111111l10'
                ],
                [
                    'type' => 'TIMESTAMP',
                    'value' => '2021-03-01T00:00:00'
                ],
                [
                    'type' => 'TIMESTAMP',
                    'value' => '2022-03-02T00:00:00'
                ],
            ]
        ];

        $data = '
            [
                {
                    "device_id": "1",
                    "device_name": "Other",
                    "total_conversions": 2385,
                    "initiator_total_conversion_items": 8311
                },
                {
                    "device_id": "2",
                    "device_name": "Desktop",
                    "total_conversions": 2450,
                    "initiator_total_conversion_items": 8177
                },
                {
                    "device_id": "3",
                    "device_name": "Mobile",
                    "total_conversions": 2285,
                    "initiator_total_conversion_items": 8321
                },
                {
                    "device_id": "4",
                    "device_name": "Tablet",
                    "total_conversions": 2350,
                    "initiator_total_conversion_items": 8468
                },
                {
                    "device_id": "5",
                    "device_name": "Bot",
                    "total_conversions": 2395,
                    "initiator_total_conversion_items": 8364
                }
            ]
        ';

        $mock = $this->createDruidMock();
        $mock->expect($sql, $params)->willRespondWith($data);

        $response = $this->jsonRequest(
            'POST',
            '/v3/brand/analytics/conversions/explode',
            [
                'date_time_ranges' => [
                    [
                        'start' => '2021-03-01T00:00:00+00:00',
                        'end' => '2022-03-02T00:00:00+00:00',
                    ]
                ],
                'scope' => [
                    'campaigns' => [
                        '111111l10'
                    ],
                ],
                'metrics' => [
                    'total_conversions',
                    'initiator_total_conversion_items'
                ],
                'group_by' => [
                    'device'
                ]
            ]
        );

//        $expectedData = json_decode($data, true);

        self::assertResponseIsSuccessful();
        self::assertEquals(json_decode($data, true), $response->getData());
    }
}