Skip to content

Commit

Permalink
test: cover SessionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Feb 10, 2024
1 parent 50b5dee commit c18ebde
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/SessionManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use NotificationChannels\Bluesky\BlueskyClient;
use NotificationChannels\Bluesky\SessionManager;
use NotificationChannels\Bluesky\Tests\Factories\BlueskyClientResponseFactory;

test('`getIdentity` generates an identity when none exist', function () {
BlueskyClientResponseFactory::fake([
BlueskyClient::CREATE_SESSION_ENDPOINT => ['handle' => 'owo'],
BlueskyClient::REFRESH_SESSION_ENDPOINT => ['handle' => 'uwu'],
]);

/** @var SessionManager */
$session = resolve(SessionManager::class);
$identity = $session->getIdentity();

expect($identity)->handle->toBe('uwu');
});

// Note: this is the same test as above, but the test above
// will need to be changed if/when we decide not to refresh
// sessions if they are not close to their expiration date
test('`getIdentity` refreshes the session automatically', function () {
BlueskyClientResponseFactory::fake([
BlueskyClient::CREATE_SESSION_ENDPOINT => ['handle' => 'owo'],
BlueskyClient::REFRESH_SESSION_ENDPOINT => ['handle' => 'uwu'],
]);

/** @var SessionManager */
$session = resolve(SessionManager::class);
$identity = $session->getIdentity();

expect($identity)->handle->toBe('uwu');
});

0 comments on commit c18ebde

Please sign in to comment.