jonnybarnes.uk/tests/Feature/SwarmTest.php
Jonny Barnes e3fff4b9a8 Squashed commit of the following:
commit 41ab44ed1d86a1d0788089cf2d79e3c9ab8e2ba6
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Aug 9 20:58:13 2017 +0100

    Add a test for a swarm checkin with no text

commit b4986ba3207374d11438e00d05a6f1ae1720bd49
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Aug 9 20:57:44 2017 +0100

    A migration that makes the note column of the notes table nullable

commit 80ac4d38c992e59733f60e844f376e36507fb8ee
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Aug 9 20:57:04 2017 +0100

    Don’t fail when the text content of a note is empty

commit 874acdd3b31028c06d19cdbe9ef34bbc9660a704
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Aug 9 20:55:12 2017 +0100

    Allow no content for the actual note, maybe its just a picture. Also provide some context for swarm checkins
2017-08-09 20:59:22 +01:00

106 lines
3.6 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class SwarmTest extends TestCase
{
use DatabaseTransactions;
public function test_faked_ownyourswarm_request()
{
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[
'value' => 'My first #checkin using Example Product',
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
]],
'checkin' => [[
'type' => ['h-card'],
'properties' => [
'name' => ['Awesome Venue'],
'url' => ['https://foursquare.com/v/123456'],
'latitude' => ['1.23'],
'longitude' => ['4.56'],
],
]],
],
],
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
);
$response
->assertStatus(201)
->assertJson(['response' => 'created']);
$this->assertDatabaseHas('places', [
'external_urls' => '{"foursquare": "https://foursquare.com/v/123456"}'
]);
$this->assertDatabaseHas('notes', [
'swarm_url' => 'https://www.swarmapp.com/checkin/abc'
]);
}
public function test_faked_ownyourswarm_request_with_no_text_content()
{
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/def'],
'checkin' => [[
'type' => ['h-card'],
'properties' => [
'name' => ['Awesomer Venue'],
'url' => ['https://foursquare.com/v/654321'],
'latitude' => ['3.21'],
'longitude' => ['6.54'],
],
]],
],
],
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
);
$response
->assertStatus(201)
->assertJson(['response' => 'created']);
$this->assertDatabaseHas('places', [
'external_urls' => '{"foursquare": "https://foursquare.com/v/654321"}'
]);
$this->assertDatabaseHas('notes', [
'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;
}
}