Handle Appstore server-to-server notifications in Laravel or Lumen projects for auto-renewable subscriptions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

5 years ago
<?php
namespace Appvise\AppStoreNotifications\Tests;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Route;
5 years ago
use Appvise\AppStoreNotifications\Model\AppleNotification;
5 years ago
class IntegrationTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
Queue::fake();
Route::post('/apple/server/notifications', "\Appvise\AppStoreNotifications\WebhooksController");
config(
[
'appstore-server-notifications.jobs' => [
5 years ago
'initial_buy' => DummyJob::class,
5 years ago
],
'appstore-server-notifications.shared_secret' => 'VALID_APPLE_PASSWORD',
]
);
}
/** @test */
public function it_can_handle_a_valid_request()
{
5 years ago
$payload = include_once __DIR__.'/__fixtures__/request.php';
$payload['password'] = 'VALID_APPLE_PASSWORD';
5 years ago
$this
->postJson('/apple/server/notifications', $payload)
->assertSuccessful();
$this->assertCount(1, AppleNotification::get());
$notification = AppleNotification::first();
$this->assertEquals('initial_buy', $notification->type);
$this->assertInstanceOf(AppleNotification::class, $notification);
Queue::assertPushed(DummyJob::class);
}
/** @test */
public function a_request_with_an_invalid_password_wont_be_logged()
{
5 years ago
$payload = include_once __DIR__.'/__fixtures__/request.php';
$payload['password'] = 'NON_VALID_APPLE_PASSWORD';
5 years ago
$this
->postJson('/apple/server/notifications', $payload)
->assertStatus(400);
$this->assertCount(0, AppleNotification::get());
$this->assertNull(AppleNotification::first());
Queue::assertNotPushed(DummyJob::class);
}
/** @test */
public function a_request_with_an_invalid_payload_will_be_logged_but_jobs_will_not_be_dispatched()
{
$payload = ['payload' => 'INVALID'];
$this
->postJson('/apple/server/notifications', $payload)
->assertStatus(500);
Queue::assertNotPushed(DummyJob::class);
}
}