generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
use Pirsch\Facades\Pirsch; | ||
|
||
it('can track request', function () { | ||
config(['pirsch.token' => 'test_token']); | ||
Http::fake([ | ||
'https://api.pirsch.io/api/v1/hit' => Http::response(), | ||
]); | ||
|
||
Pirsch::track(); | ||
$this->get('/'); | ||
|
||
Http::assertSent(function (Request $request) { | ||
expect($request->url())->toBe('https://api.pirsch.io/api/v1/hit'); | ||
expect($request->hasHeader('Authorization', 'Bearer test_token'))->toBeTrue(); | ||
expect($request->data())->toBe([ | ||
'url' => 'http://localhost', | ||
'ip' => '127.0.0.1', | ||
'user_agent' => 'Symfony', | ||
'accept_language' => 'en-us,en;q=0.5', | ||
'sec_ch_ua' => null, | ||
'sec_ch_ua_mobile' => null, | ||
'sec_ch_ua_platform' => null, | ||
'sec_ch_ua_platform_version' => null, | ||
'sec_ch_width' => null, | ||
'sec_ch_viewport_width' => null, | ||
'referrer' => null, | ||
]); | ||
|
||
return true; | ||
}); | ||
}); | ||
|
||
it('can send an event', function () { | ||
config(['pirsch.token' => 'test_token']); | ||
Http::fake([ | ||
'https://api.pirsch.io/api/v1/event' => Http::response(), | ||
]); | ||
|
||
Pirsch::track('name', ['meta' => 'data']); | ||
$this->get('/'); | ||
|
||
Http::assertSent(function (Request $request) { | ||
expect($request->url())->toBe('https://api.pirsch.io/api/v1/event'); | ||
expect($request->hasHeader('Authorization', 'Bearer test_token'))->toBeTrue(); | ||
expect($request->data())->toBe([ | ||
'url' => 'http://localhost', | ||
'ip' => '127.0.0.1', | ||
'user_agent' => 'Symfony', | ||
'accept_language' => 'en-us,en;q=0.5', | ||
'sec_ch_ua' => null, | ||
'sec_ch_ua_mobile' => null, | ||
'sec_ch_ua_platform' => null, | ||
'sec_ch_ua_platform_version' => null, | ||
'sec_ch_width' => null, | ||
'sec_ch_viewport_width' => null, | ||
'referrer' => null, | ||
'event_name' => 'name', | ||
'event_meta' => [ | ||
'meta' => 'data', | ||
], | ||
]); | ||
|
||
return true; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Pirsch\Facades\Pirsch; | ||
use Pirsch\Http\Middleware\TrackPageview; | ||
|
||
it('handles request', function () { | ||
Pirsch::shouldReceive('track') | ||
->once(); | ||
|
||
Route::middleware(TrackPageview::class) | ||
->get('/', fn () => 'Hello World'); | ||
|
||
$this->get('/'); | ||
|
||
expect(true)->toBeTrue(); | ||
}); | ||
|
||
it('skips redirects', function () { | ||
Pirsch::spy(); | ||
|
||
Route::middleware(TrackPageview::class) | ||
->get('/', fn () => redirect('/home')); | ||
|
||
$this->get('/'); | ||
|
||
Pirsch::shouldNotHaveBeenCalled(); | ||
expect(true)->toBeTrue(); | ||
}); | ||
|
||
it('skips livewire', function () { | ||
Pirsch::spy(); | ||
|
||
Route::middleware(TrackPageview::class) | ||
->get('/', fn () => 'Hello World'); | ||
|
||
$this->get('/', ['X-Livewire' => 'true']); | ||
|
||
Pirsch::shouldNotHaveBeenCalled(); | ||
expect(true)->toBeTrue(); | ||
}); | ||
|
||
it('skips telescope', function () { | ||
Pirsch::spy(); | ||
|
||
Route::middleware(TrackPageview::class) | ||
->get('telescope/test', fn () => 'Hello World'); | ||
|
||
$this->get('/telescope/test'); | ||
|
||
Pirsch::shouldNotHaveBeenCalled(); | ||
expect(true)->toBeTrue(); | ||
}); |