-
Notifications
You must be signed in to change notification settings - Fork 0
feat: default analytics to the dedicated ingest service #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Supertab\Connect\Tests; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use ReflectionProperty; | ||
| use Supertab\Connect\Analytics\DeferredAnalyticsTransport; | ||
| use Supertab\Connect\Analytics\HttpAnalyticsTransport; | ||
| use Supertab\Connect\SupertabConnect; | ||
|
|
||
| /** | ||
| * Analytics base URL resolution — the relay targets the dedicated ingest | ||
| * service by default, independent of the API base URL used for token | ||
| * acquisition / JWKS / verification. Mirrors the TypeScript SDK's | ||
| * "analytics base URL resolution" suite. | ||
| */ | ||
| final class SupertabConnectAnalyticsBaseUrlTest extends TestCase | ||
| { | ||
| private const DEFAULT_INGEST = 'https://ingest-connect.supertab.co'; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| SupertabConnect::resetInstance(); | ||
| SupertabConnect::setBaseUrl('https://api-connect.supertab.co'); | ||
| // Reset to the class's declared default (not the DEFAULT_INGEST constant), | ||
| // so the defaults test genuinely exercises the declared value and a changed | ||
| // default fails against the constant instead of being masked by setUp. | ||
| SupertabConnect::setAnalyticsBaseUrl($this->declaredDefaultAnalyticsBaseUrl()); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| SupertabConnect::resetInstance(); | ||
| SupertabConnect::setBaseUrl('https://api-connect.supertab.co'); | ||
| SupertabConnect::setAnalyticsBaseUrl($this->declaredDefaultAnalyticsBaseUrl()); | ||
| } | ||
|
|
||
| private function declaredDefaultAnalyticsBaseUrl(): string | ||
| { | ||
| return (new ReflectionProperty(SupertabConnect::class, 'analyticsBaseUrl'))->getDefaultValue(); | ||
| } | ||
|
|
||
| /** | ||
| * Extract the base URL wired into the default HTTP analytics transport | ||
| * (unwrapping the deferred decorator). | ||
| */ | ||
| private function relayBaseUrlOf(SupertabConnect $stc): string | ||
| { | ||
| $transport = (new ReflectionProperty(SupertabConnect::class, 'analyticsTransport'))->getValue($stc); | ||
| $this->assertInstanceOf(DeferredAnalyticsTransport::class, $transport); | ||
|
|
||
| $inner = (new ReflectionProperty(DeferredAnalyticsTransport::class, 'inner'))->getValue($transport); | ||
| $this->assertInstanceOf(HttpAnalyticsTransport::class, $inner); | ||
|
|
||
| return (new ReflectionProperty(HttpAnalyticsTransport::class, 'baseUrl'))->getValue($inner); | ||
| } | ||
|
|
||
| public function test_defaults_analytics_relay_to_ingest_host(): void | ||
| { | ||
| $stc = new SupertabConnect(apiKey: 'k', analyticsEnabled: true); | ||
|
|
||
| $this->assertSame(self::DEFAULT_INGEST, $this->relayBaseUrlOf($stc)); | ||
| } | ||
|
|
||
| public function test_constructor_analytics_base_url_overrides_default_host(): void | ||
| { | ||
| $stc = new SupertabConnect( | ||
| apiKey: 'k', | ||
| analyticsEnabled: true, | ||
| analyticsBaseUrl: 'https://ingest.example.com', | ||
| ); | ||
|
|
||
| $this->assertSame('https://ingest.example.com', $this->relayBaseUrlOf($stc)); | ||
| } | ||
|
|
||
| public function test_set_analytics_base_url_overrides_default_host(): void | ||
| { | ||
| SupertabConnect::setAnalyticsBaseUrl('https://static.example.com'); | ||
|
|
||
| $stc = new SupertabConnect(apiKey: 'k', analyticsEnabled: true); | ||
|
|
||
| $this->assertSame('https://static.example.com', $this->relayBaseUrlOf($stc)); | ||
| } | ||
|
|
||
| public function test_constructor_analytics_base_url_beats_static_setter(): void | ||
| { | ||
| SupertabConnect::setAnalyticsBaseUrl('https://static.example.com'); | ||
|
|
||
| $stc = new SupertabConnect( | ||
| apiKey: 'k', | ||
| analyticsEnabled: true, | ||
| analyticsBaseUrl: 'https://perinstance.example.com', | ||
| ); | ||
|
|
||
| $this->assertSame('https://perinstance.example.com', $this->relayBaseUrlOf($stc)); | ||
| } | ||
|
|
||
| public function test_analytics_host_is_independent_of_set_base_url(): void | ||
| { | ||
| SupertabConnect::setBaseUrl('https://api.example.com'); | ||
|
|
||
| $stc = new SupertabConnect(apiKey: 'k', analyticsEnabled: true); | ||
|
|
||
| $this->assertSame(self::DEFAULT_INGEST, $this->relayBaseUrlOf($stc)); | ||
| } | ||
|
|
||
| public function test_get_analytics_base_url_reflects_setter(): void | ||
| { | ||
| SupertabConnect::setAnalyticsBaseUrl('https://x.example.com'); | ||
|
|
||
| $this->assertSame('https://x.example.com', SupertabConnect::getAnalyticsBaseUrl()); | ||
| } | ||
|
|
||
| public function test_set_analytics_base_url_trims_trailing_slash(): void | ||
| { | ||
| SupertabConnect::setAnalyticsBaseUrl('https://x.example.com/'); | ||
|
|
||
| $this->assertSame('https://x.example.com', SupertabConnect::getAnalyticsBaseUrl()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.