Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfinney committed Jun 30, 2020
2 parents 95d8c2b + 480d5fc commit ddf2c5f
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Install QuickBooks PHP Client:
$ composer require spinen/laravel-quickbooks-client
```

The package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.
The package uses the [auto registration feature](https://laravel.com/docs/packages#package-discovery) of Laravel.

## Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up()
$user_id_type = DB::getSchemaBuilder()
->getColumnType('users', 'id') === 'bigint' ? 'unsignedBigInteger' : 'unsignedInteger';

$table->unsignedBigInteger('id');
$table->bigIncrements('id');
$table->{$user_id_type}('user_id');
$table->unsignedBigInteger('realm_id');
$table->longtext('access_token');
Expand Down
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function configureLogging()
return $this->data_service->enableLog();
}
} catch (Exception $e) {
// TODO: Figure out what to do with this exception
}

return $this->data_service->disableLog();
Expand Down
11 changes: 5 additions & 6 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ public function connect(QuickBooks $quickbooks, ViewFactory $view_factory)
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
* @throws \Exception
*/
public function disconnect(Redirector $redirector, QuickBooks $quickbooks)
public function disconnect(Redirector $redirector, Request $request, QuickBooks $quickbooks)
{
$quickbooks->deleteToken();

// TODO: Figure out where to put this in session & remove Facade
Alert::success('Disconnected from QuickBooks')
->flash();
$request->session()->flash('success', 'Disconnected from QuickBooks');

return $redirector->back();
}
Expand All @@ -84,7 +82,8 @@ public function token(Redirector $redirector, Request $request, QuickBooks $quic
// TODO: Deal with exceptions
$quickbooks->exchangeCodeForToken($request->get('code'), $request->get('realmId'));

return $redirector->intended($url_generator->route('quickbooks.connect'))
->with('success', 'Connected to QuickBooks');
$request->session()->flash('success', 'Connected to QuickBooks');

return $redirector->intended($url_generator->route('quickbooks.connect'));
}
}
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function it_returns_a_data_service_with_oauth_token_when_valid_access_tok
/**
* @test
*/
public function it_returns_a_data_service_with_refreshed_token_when_acccess_token_expired_but_refresh_token_valid()
public function it_returns_a_data_service_with_refreshed_token_when_access_token_expired_but_refresh_token_valid()
{
$this->expectException(ServiceException::class);

Expand Down
2 changes: 1 addition & 1 deletion tests/HasQuickBooksTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function it_can_be_constructed()
*/
public function it_has_a_hasOne_relationship_to_token()
{
// The stub is just returing the relationship name, so making sure that it is the Token class
// The stub is just returning the relationship name, so making sure that it is the Token class
$this->assertEquals(Token::class, $this->user->quickBooksToken());
}
}
97 changes: 97 additions & 0 deletions tests/Http/Controllers/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace Spinen\QuickBooks\Http\Controllers;

use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Session\Store;
use Mockery;
use Mockery\Mock;
use Spinen\QuickBooks\Client as QuickBooks;
Expand Down Expand Up @@ -31,6 +36,21 @@ class ControllerTest extends TestCase
*/
protected $quickbooks_mock;

/**
* @var Mock
*/
protected $redirector_mock;

/**
* @var Mock
*/
protected $request_mock;

/**
* @var Mock
*/
protected $session_mock;

/**
* @var Mock
*/
Expand All @@ -45,6 +65,9 @@ protected function setUp(): void
{
$this->data_service_mock = Mockery::mock();
$this->quickbooks_mock = Mockery::mock(QuickBooks::class);
$this->redirector_mock = Mockery::mock(Redirector::class);
$this->request_mock = Mockery::mock(Request::class);
$this->session_mock = Mockery::mock(Store::class);
$this->view_factory_mock = Mockery::mock(ViewFactory::class);
$this->view_mock = Mockery::mock(View::class);

Expand Down Expand Up @@ -129,4 +152,78 @@ public function it_shows_view_to_disconnect_if_account_linked()

$this->controller->connect($this->quickbooks_mock, $this->view_factory_mock);
}

/**
* @test
*/
public function it_disconnects_from_quickbooks_when_requested()
{
$this->request_mock->shouldReceive('session')
->once()
->andReturn($this->session_mock);

$this->session_mock->shouldReceive('flash')
->once()
->withAnyArgs();

$this->redirector_mock->shouldReceive('back')
->once()
->andReturn(new RedirectResponse('/test', 302));

$this->quickbooks_mock->shouldReceive('deleteToken')
->once()
->withNoArgs();

$result = $this->controller->disconnect($this->redirector_mock, $this->request_mock, $this->quickbooks_mock);

$this->assertInstanceOf(RedirectResponse::class, $result);
}

/**
* @test
*/
public function it_finishes_connecting_to_quickbooks_when_given_a_valid_token_by_quickbooks()
{
$this->url_generator_mock = Mockery::mock(UrlGenerator::class);

$this->quickbooks_mock->shouldReceive('exchangeCodeForToken')
->once()
->withArgs(['code', 'realmId']);

$this->request_mock->shouldReceive('get')
->once()
->withArgs(['code'])
->andReturn('code');

$this->request_mock->shouldReceive('get')
->once()
->withArgs(['realmId'])
->andReturn('realmId');

$this->request_mock->shouldReceive('session')
->once()
->andReturn($this->session_mock);

$this->session_mock->shouldReceive('flash')
->once()
->withAnyArgs();

$this->redirector_mock->shouldReceive('intended')
->once()
->withAnyArgs()
->andReturn(new RedirectResponse('/test', 302));

$this->url_generator_mock->shouldReceive('route')
->withArgs(['quickbooks.connect'])
->once();

$result = $this->controller->token(
$this->redirector_mock,
$this->request_mock,
$this->quickbooks_mock,
$this->url_generator_mock
);

$this->assertInstanceOf(RedirectResponse::class, $result);
}
}

0 comments on commit ddf2c5f

Please sign in to comment.