diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index 41720505..925d0932 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -3,13 +3,14 @@ namespace Tests\Feature; use Tests\TestCase; +use Tests\TestToken; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Hmac\Sha256; use Illuminate\Foundation\Testing\DatabaseTransactions; class MicropubControllerTest extends TestCase { - use DatabaseTransactions; + use DatabaseTransactions, TestToken; /** * Test a GET request for the micropub endpoint without a token gives a @@ -314,42 +315,4 @@ class MicropubControllerTest extends TestCase 'swarm_url' => 'https://www.swarmapp.com/checkin/123' ]); } - - /** - * Generate a valid token to be used in the tests. - * - * @return Lcobucci\JWT\Token\Plain $token - */ - private function getToken() - { - $signer = new Sha256(); - $token = (new Builder()) - ->set('client_id', 'https://quill.p3k.io') - ->set('me', 'https://jonnybarnes.localhost') - ->set('scope', 'create update') - ->set('issued_at', time()) - ->sign($signer, env('APP_KEY')) - ->getToken(); - - return $token; - } - - /** - * Generate an invalid token to be used in the tests. - * - * @return Lcobucci\JWT\Token\Plain $token - */ - private function getInvalidToken() - { - $signer = new Sha256(); - $token = (new Builder()) - ->set('client_id', 'https://quill.p3k.io') - ->set('me', 'https://jonnybarnes.localhost') - ->set('scope', 'view') //error here - ->set('issued_at', time()) - ->sign($signer, env('APP_KEY')) - ->getToken(); - - return $token; - } } diff --git a/tests/Feature/OwnYourGramTest.php b/tests/Feature/OwnYourGramTest.php index ca0c3549..e071b511 100644 --- a/tests/Feature/OwnYourGramTest.php +++ b/tests/Feature/OwnYourGramTest.php @@ -3,13 +3,14 @@ namespace Tests\Feature; use Tests\TestCase; +use Tests\TestToken; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Hmac\Sha256; use Illuminate\Foundation\Testing\DatabaseTransactions; class OwnYourGramTest extends TestCase { - use DatabaseTransactions; + use DatabaseTransactions, TestToken; public function test_ownyourgram_post() { @@ -40,18 +41,4 @@ class OwnYourGramTest extends TestCase 'instagram_url' => 'https://www.instagram.com/p/BVC_nVTBFfi/' ]); } - - private function getToken() - { - $signer = new Sha256(); - $token = (new Builder()) - ->set('client_id', 'https://ownyourgram.com') - ->set('me', config('app.url')) - ->set('scope', 'create') - ->set('issued_at', time()) - ->sign($signer, env('APP_KEY')) - ->getToken(); - - return $token; - } } diff --git a/tests/Feature/SwarmTest.php b/tests/Feature/SwarmTest.php index 6e553102..25780dc7 100644 --- a/tests/Feature/SwarmTest.php +++ b/tests/Feature/SwarmTest.php @@ -3,13 +3,14 @@ namespace Tests\Feature; use Tests\TestCase; +use Tests\TestToken; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Hmac\Sha256; use Illuminate\Foundation\Testing\DatabaseTransactions; class SwarmTest extends TestCase { - use DatabaseTransactions; + use DatabaseTransactions, TestToken; public function test_faked_ownyourswarm_request() { @@ -82,23 +83,4 @@ class SwarmTest extends TestCase 'swarm_url' => 'https://www.swarmapp.com/checkin/def' ]); } - - /** - * Generate a valid token to be used in the tests. - * - * @return Lcobucci\JWT\Token\Plain $token - */ - private function getToken() - { - $signer = new Sha256(); - $token = (new Builder()) - ->set('client_id', 'https://ownyourswarm.p3k.io') - ->set('me', 'https://jonnybarnes.localhost') - ->set('scope', 'create update') - ->set('issued_at', time()) - ->sign($signer, env('APP_KEY')) - ->getToken(); - - return $token; - } }