Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Fixing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Apr 12, 2019
1 parent f93fb2b commit 9314bbb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 60 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": ">=7.1.0",
"laravel/framework": "~5.6",
"ohmybrew/basic-shopify-api": "~5.1",
"ohmybrew/basic-shopify-api": "~5.3",
"doctrine/dbal": "~2.5"
},
"require-dev":{
Expand Down
6 changes: 3 additions & 3 deletions src/ShopifyApp/Services/AuthShopHandler.php
Expand Up @@ -51,18 +51,18 @@ public function __construct(shop $shop)
/**
* Builds the authentication URL for a shop.
*
* @param string $mode The mode of grant ("offline"/"per-user").
* @param string|null $mode The mode of grant ("offline"/"per-user").
*
* @return string
*/
public function buildAuthUrl(string $mode)
public function buildAuthUrl($mode = null)
{
// Determine the type of mode
// Grab the authentication URL
return $this->api->getAuthUrl(
Config::get('shopify-app.api_scopes'),
URL::secure(Config::get('shopify-app.api_redirect')),
$mode
$mode ?? 'offline'
);
}

Expand Down
70 changes: 14 additions & 56 deletions tests/Services/AuthShopHandlerTest.php
Expand Up @@ -26,31 +26,25 @@ public function setUp() : void
Config::set('shopify-app.api_class', new ApiStub());
}

public function testStoresSession()
{
// Create the shop
$shop = factory(Shop::class)->create();

// Store the session
$as = new AuthShopHandler($shop->shopify_domain);
$as->storeSession();

$this->assertEquals($shop->shopify_domain, Session::get('shopify_domain'));
}

public function testAuthUrl()
{
// Create the shop
$shop = factory(Shop::class)->create();

// Get the URL
$as = new AuthShopHandler($shop->shopify_domain);
$url = $as->buildAuthUrl();
$as = new AuthShopHandler($shop);

$url = $as->buildAuthUrl(null);
$this->assertEquals(
"https://{$shop->shopify_domain}/admin/oauth/authorize?client_id=&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate",
$url
);

$url = $as->buildAuthUrl('per-user');
$this->assertEquals(
"https://{$shop->shopify_domain}/admin/oauth/authorize?client_id=&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate&grant_options%5B%5D=per-user",
$url
);
}

public function testVerifyRequest()
Expand All @@ -76,28 +70,7 @@ public function testVerifyRequest()

$this->assertTrue($result);
}

public function testStoresAccessToken()
{
// Stub the responses
ApiStub::stubResponses([
'get_access_token',
]);

// Create the shop
$shop = factory(Shop::class)->create();

// Run the call
$currentToken = $shop->shopify_token;
$as = new AuthShopHandler($shop->shopify_domain);
$as->storeAccessToken('1234');

// Refresh
$shop->refresh();

$this->assertTrue($currentToken !== $shop->shopify_token);
}

/*
public function testStoresAccessTokenForTrashedShop()
{
// Stub the responses
Expand All @@ -119,7 +92,7 @@ public function testStoresAccessTokenForTrashedShop()
$this->assertTrue($currentToken !== $shop->shopify_token);
}

*/
public function testJobsDoNotRun()
{
// Fake the queue
Expand All @@ -129,29 +102,14 @@ public function testJobsDoNotRun()
$shop = factory(Shop::class)->create();

// Run the jobs
$as = new AuthShopHandler($shop->shopify_domain);
$as = new AuthShopHandler($shop);
$as->dispatchJobs();

// No jobs should be pushed when theres no config for them
Queue::assertNotPushed(WebhookInstaller::class);
Queue::assertNotPushed(ScripttagInstaller::class);
}

/**
* @expectedException Exception
*/
public function testJobsDoNotRunForMissingToken()
{
// Create the shop
$shop = factory(Shop::class)->create([
'shopify_token' => null,
]);

// Run the jobs
$as = new AuthShopHandler($shop->shopify_domain);
$as->dispatchJobs();
}

public function testJobsRun()
{
// Fake the queue
Expand Down Expand Up @@ -181,7 +139,7 @@ public function testJobsRun()
$shop = factory(Shop::class)->create();

// Run the jobs
$as = new AuthShopHandler($shop->shopify_domain);
$as = new AuthShopHandler($shop);
$as->dispatchJobs();

// No jobs should be pushed when theres no config for them
Expand All @@ -207,7 +165,7 @@ public function testAfterAuthenticateSingleJobRuns()
$shop = factory(Shop::class)->create();

// Run the jobs
$as = new AuthShopHandler($shop->shopify_domain);
$as = new AuthShopHandler($shop);
$as->dispatchJobs();

Queue::assertPushed($jobClass);
Expand All @@ -226,7 +184,7 @@ public function testAfterAuthenticateInlineJobRuns()
$shop = factory(Shop::class)->create();

// Run the jobs
$as = new AuthShopHandler($shop->shopify_domain);
$as = new AuthShopHandler($shop);

$this->assertTrue($as->dispatchJobs());
}
Expand Down

0 comments on commit 9314bbb

Please sign in to comment.