Closed usmanpakistan closed 1 year ago
@usmanpakistan thanks for submitting the PR. It looks good but codecov is complaining because no unit tests have been set up for the new file.
Can you write a couple test for the middleware please.
Hi @Kyon147 I did try to create a test case (not good at doing it). However, need some help. Idea is to load scopes from Shopify Config file, remove one of the scopes and then run it through the middleware. The middleware will match the installed scope with the scope in the Shopify config file. However, I cannot figure out how to emulate the Shopify API calls. Can you help me out here?
<?php
namespace Osiset\ShopifyApp\Test\Http\Middleware;
use Illuminate\Auth\AuthManager;
use Osiset\ShopifyApp\Test\TestCase;
use Osiset\ShopifyApp\Util;
class VerifyScopesTest extends TestCase{
/**
* @var AuthManager
*/
protected $auth;
public function setUp(): void
{
parent::setUp();
$this->auth = $this->app->make(AuthManager::class);
}
public function testMissingScopes(): void
{
$shop = factory($this->model)->create();
$this->auth->login($shop);
// Get current Scopes
$scopes = $this->app['config']->get('shopify-app.access_scopes');
$scopes = explode(',', $scopes);
unset($scopes[0]);
$newScopes = implode(',',$scopes);
$this->app['config']->set('shopify-app.access_scopes',$newScopes);
// Run the middleware
$result = $this->runMiddleware(BillableMiddleware::class);
$this->assertStatus(302);
}
}
No worries @usmanpakistan if you push up the test I'll take a look and edit it 👍
@Kyon147 Test Case added
Any update on the PR?
Any update on the PR?
It's on my list to look at next - will see if I can squeeze this in at the weekend
This PR adds code to resolve issues reported in #186 #185