mirror of
https://github.com/wearepixel/laravel-quickbooks.git
synced 2026-11-14 14:01:46 +00:00
test: add tests for upgrade-sensitive areas
- Token model structure: verify $casts has datetime fields, $fillable is complete, and $table is set correctly (catches $dates→$casts regression) - ClientServiceProvider: verify DeferrableProvider interface is implemented and provides() returns Client::class (catches $defer regression) - Token parseOauthToken: verify stored values and Carbon types, not just that mock methods were called - Client setToken: verify DataService cache is cleared on token change - Client delegation: verify hasValidAccessToken/hasValidRefreshToken delegate to Token correctly
This commit is contained in:
@@ -145,3 +145,54 @@
|
||||
|
||||
expect($this->client->deleteToken())->toBeInstanceOf(Client::class);
|
||||
});
|
||||
|
||||
it('clears cached data service when token is changed', function () {
|
||||
$this->token_mock
|
||||
->shouldReceive('getAttribute')
|
||||
->with('hasValidAccessToken')
|
||||
->andReturnFalse();
|
||||
|
||||
$this->token_mock
|
||||
->shouldReceive('getAttribute')
|
||||
->with('hasValidRefreshToken')
|
||||
->andReturnFalse();
|
||||
|
||||
$first = $this->client->getDataService();
|
||||
|
||||
$new_token = Mockery::mock(Token::class);
|
||||
$new_token
|
||||
->shouldReceive('getAttribute')
|
||||
->with('hasValidAccessToken')
|
||||
->andReturnFalse();
|
||||
|
||||
$new_token
|
||||
->shouldReceive('getAttribute')
|
||||
->with('hasValidRefreshToken')
|
||||
->andReturnFalse();
|
||||
|
||||
$this->client->setToken($new_token);
|
||||
|
||||
$second = $this->client->getDataService();
|
||||
|
||||
expect($second)->not->toBe($first);
|
||||
});
|
||||
|
||||
it('delegates hasValidAccessToken to token', function () {
|
||||
$this->token_mock
|
||||
->shouldReceive('getAttribute')
|
||||
->once()
|
||||
->with('hasValidAccessToken')
|
||||
->andReturnTrue();
|
||||
|
||||
expect($this->client->hasValidAccessToken())->toBeTrue();
|
||||
});
|
||||
|
||||
it('delegates hasValidRefreshToken to token', function () {
|
||||
$this->token_mock
|
||||
->shouldReceive('getAttribute')
|
||||
->once()
|
||||
->with('hasValidRefreshToken')
|
||||
->andReturnFalse();
|
||||
|
||||
expect($this->client->hasValidRefreshToken())->toBeFalse();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user