php-plug-altum/tests/Analytics/ClientTest.php

41 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
use Core\Plug\Altum\Analytics\Client;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
$this->client = new Client(
baseUrl: 'https://analytics.test',
adminApiKey: 'admin-key',
userApiKey: 'user-key',
);
Http::fake(['*' => Http::response(['data' => []], 200)]);
});
it('lists websites', function () {
$this->client->websites();
Http::assertSent(fn ($r) => str_contains($r->url(), '/api/websites/'));
});
it('gets a website', function () {
$this->client->website(1);
Http::assertSent(fn ($r) => str_contains($r->url(), '/api/websites/1'));
});
it('creates a website', function () {
$this->client->createWebsite(['name' => 'Test', 'host' => 'example.com']);
Http::assertSent(fn ($r) => $r->method() === 'POST' && str_contains($r->url(), '/api/websites'));
});
it('fetches statistics', function () {
$this->client->statistics(['website_id' => 1]);
Http::assertSent(fn ($r) => str_contains($r->url(), '/api/statistics/'));
});
it('creates annotations', function () {
$this->client->createAnnotation(['website_id' => 1, 'title' => 'Deploy']);
Http::assertSent(fn ($r) => str_contains($r->url(), '/api/annotations'));
});