Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Appvise\AppStoreNotifications\Tests;
|
||||
|
||||
use Appvise\AppStoreNotifications\Model\NotificationPayload;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
||||
class DummyJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $payload;
|
||||
|
||||
public function __construct(NotificationPayload $payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
function handle()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Appvise\AppStoreNotifications\Tests;
|
||||
|
||||
use Appvise\AppStoreNotifications\Model\AppleNotification;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
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' => [
|
||||
'initial_buy' => DummyJob::class
|
||||
],
|
||||
'appstore-server-notifications.shared_secret' => 'VALID_APPLE_PASSWORD',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_handle_a_valid_request()
|
||||
{
|
||||
$payload = include_once __DIR__ . '/__fixtures__/request.php';
|
||||
|
||||
$payload['password'] = "VALID_APPLE_PASSWORD";
|
||||
|
||||
$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()
|
||||
{
|
||||
$payload = include_once __DIR__ . '/__fixtures__/request.php';
|
||||
$payload['password'] = "NON_VALID_APPLE_PASSWORD";
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Appvise\AppStoreNotifications\Tests;
|
||||
|
||||
use Appvise\AppStoreNotifications\NotificationsServiceProvider;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Orchestra\Testbench\TestCase as OrchestraTestCase;
|
||||
use CreateAppleNotificationsTable;
|
||||
|
||||
abstract class TestCase extends OrchestraTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the environment.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$app['config']->set('database.default', 'sqlite');
|
||||
$app['config']->set('database.connections.sqlite', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
|
||||
config(['appstore-server-notifications.shared_secret' => 'test_shared_secret']);
|
||||
}
|
||||
|
||||
protected function setUpDatabase()
|
||||
{
|
||||
include_once __DIR__.'/../database/migrations/create_apple_notifications_table.php.stub';
|
||||
|
||||
(new CreateAppleNotificationsTable())->up();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
NotificationsServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function disableExceptionHandling()
|
||||
{
|
||||
$this->app->instance(ExceptionHandler::class, new class extends Handler {
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function report(Exception $e)
|
||||
{
|
||||
}
|
||||
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
throw $exception;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
return json_decode('{
|
||||
"environment": "Sandbox",
|
||||
"notification_type": "INITIAL_BUY",
|
||||
"password": "TEST_SHARED_SECRET",
|
||||
"cancellation_date": "2018-03-27 07:11:12 Etc/GMT",
|
||||
"cancellation_date_pst": "2018-03-27 00:11:12 America/Los_Angeles",
|
||||
"cancellation_date_ms": "1522134672000",
|
||||
"web_order_line_item_id": "1000000047417113",
|
||||
"latest_receipt": "BASE64ENCODED_RECEIPT_INFO",
|
||||
"latest_receipt_info": {},
|
||||
"latest_expired_receipt" : "BASE64ENCODED_LATEST_RECEIPT_INFO",
|
||||
"latest_expired_receipt_info": {
|
||||
"purchase_date_ms": "1521893342000",
|
||||
"original_transaction_id": "1000000577061006",
|
||||
"web_order_line_item_id": "1000000047417113",
|
||||
"product_id": "PRODUCT_ID",
|
||||
"purchase_date": "2018-03-24 12:09:02 Etc/GMT",
|
||||
"purchase_date_pst": "2018-03-24 05:09:02 America/Los_Angeles",
|
||||
"original_purchase_date": "2018-03-17 12:09:03 Etc/GMT",
|
||||
"original_purchase_date_ms": "1521288543000",
|
||||
"original_purchase_date_pst": "2018-03-17 05:09:03 America/Los_Angeles",
|
||||
"cancellation_reason": "0",
|
||||
"cancellation_date": "2018-03-27 07:11:12 Etc/GMT",
|
||||
"cancellation_date_ms": "1522134672000",
|
||||
"cancellation_date_pst": "2018-03-27 00:11:12 America/Los_Angeles",
|
||||
"expires_date": "2019-10-09 07:43:26 Etc/GMT",
|
||||
"expires_date_ms": "1570607006000",
|
||||
"expires_date_formatted": "2019-03-24 12:09:02 Etc/GMT",
|
||||
"expires_date_formatted_pst": "2019-03-24 05:09:02 America/Los_Angeles",
|
||||
"quantity": "1",
|
||||
"unique_identifier": "UNIQUE_IDENTIFIER",
|
||||
"unique_vendor_identifier": "UNIQUE_VENDOR_IDENTIFIER",
|
||||
"is_in_intro_offer_period": "false",
|
||||
"is_trial_period": "false",
|
||||
"item_id": "ITEM_ID",
|
||||
"app_item_id": "APP_ITEM_ID",
|
||||
"version_external_identifier": "VERSION_EXTERNAL_IDENTIFIER",
|
||||
"transaction_id": "1000000577069202",
|
||||
"bvrs": "2",
|
||||
"bid": "com.example.app.ios"
|
||||
},
|
||||
"auto_renew_status": "false",
|
||||
"auto_renew_product_id": "PRODUCT_ID",
|
||||
"auto_renew_status_change_date": "",
|
||||
"auto_renew_status_change_date_pst": "",
|
||||
"auto_renew_status_change_date_ms": "",
|
||||
"pending_renewal_info": [
|
||||
{
|
||||
"auto_renew_product_id": "PRODUCT_ID",
|
||||
"auto_renew_status": "1",
|
||||
"expiration_intent": "",
|
||||
"original_transaction_id": "1000000577061006",
|
||||
"is_in_billing_retry_period": "1",
|
||||
"product_id": "PRODUCT_ID",
|
||||
"price_consent_status": "0",
|
||||
"grace_period_expires_date": "",
|
||||
"grace_period_expires_date_ms": "",
|
||||
"grace_period_expires_date_pst": ""
|
||||
}
|
||||
]
|
||||
}', true
|
||||
);
|
||||
|
||||
|
||||
//{
|
||||
// "environment": "Sandbox",
|
||||
// "notification_type": "INITIAL_BUY",
|
||||
// "password": "TEST_SHARED_SECRET",
|
||||
// "cancellation_date": "2018-03-27 07:11:12 Etc/GMT",
|
||||
// "cancellation_date_pst": "2018-03-27 00:11:12 America/Los_Angeles",
|
||||
// "cancellation_date_ms": "1522134672000", // important for cancel
|
||||
// "web_order_line_item_id": "1000000047417113",
|
||||
// "latest_receipt": "BASE64ENCODED_RECEIPT_INFO",
|
||||
// "latest_receipt_info": "ARRAY_WITH_RECEIPT_INFO",
|
||||
// "latest_expired_receipt" : "BASE64ENCODED_LATEST_RECEIPT_INFO",
|
||||
// "latest_expired_receipt_info": {
|
||||
// "purchase_date_ms": "1521893342000", // important for initial buy, interactive_renewal, did_recover
|
||||
// "original_transaction_id": "1000000577061006", // important for initial buy, interactive_renewal, did_change_renewal_info, cancel, did_change_renewal_status, did_fail_to_renew, did_recover, price_increase_consent
|
||||
// "web_order_line_item_id": "1000000047417113", // important for initial buy, interactive_renewal
|
||||
// "product_id": "PRODUCT_ID", // important for initial buy, interactive_renewal, cancel, did_change_renewal_status
|
||||
// "purchase_date": "2018-03-24 12:09:02 Etc/GMT",
|
||||
// "purchase_date_pst": "2018-03-24 05:09:02 America/Los_Angeles",
|
||||
// "original_purchase_date": "2018-03-17 12:09:03 Etc/GMT",
|
||||
// "original_purchase_date_ms": "1521288543000",
|
||||
// "original_purchase_date_pst": "2018-03-17 05:09:03 America/Los_Angeles",
|
||||
// "cancellation_reason": "0",
|
||||
// "cancellation_date": "2018-03-27 07:11:12 Etc/GMT",
|
||||
// "cancellation_date_ms": "1522134672000",
|
||||
// "cancellation_date_pst": "2018-03-27 00:11:12 America/Los_Angeles",
|
||||
// "expires_date": "2019-10-09 07:43:26 Etc/GMT",
|
||||
// "expires_date_ms": "1570607006000", // important for did_recover, price_increase_consent
|
||||
// "expires_date_formatted": "2019-03-24 12:09:02 Etc/GMT",
|
||||
// "expires_date_formatted_pst": "2019-03-24 05:09:02 America/Los_Angeles",
|
||||
// "quantity": "1",
|
||||
// "unique_identifier": "UNIQUE_IDENTIFIER",
|
||||
// "unique_vendor_identifier": "UNIQUE_VENDOR_IDENTIFIER",
|
||||
// "is_in_intro_offer_period": "false",
|
||||
// "is_trial_period": "false",
|
||||
// "item_id": "ITEM_ID",
|
||||
// "app_item_id": "APP_ITEM_ID",
|
||||
// "version_external_identifier": "VERSION_EXTERNAL_IDENTIFIER",
|
||||
// "transaction_id": "1000000577069202",
|
||||
// "bvrs": "2",
|
||||
// "bid": "com.example.ios.app"
|
||||
// },
|
||||
// "auto_renew_status": "false", // important for did_change_renewal_status
|
||||
// "auto_renew_product_id": "PRODUCT_ID", // important for did_change_renewal_info
|
||||
// "auto_renew_status_change_date": "",
|
||||
// "auto_renew_status_change_date_pst": "",
|
||||
// "auto_renew_status_change_date_ms": "", // important for did_change_renewal_status
|
||||
// "pending_renewal_info": [ // important for did_fail_to_renew
|
||||
// {
|
||||
// "auto_renew_product_id": "PRODUCT_ID",
|
||||
// "auto_renew_status": "1",
|
||||
// "expiration_intent": "",
|
||||
// "original_transaction_id": "1000000577061006",
|
||||
// "is_in_billing_retry_period": "1",
|
||||
// "product_id": "PRODUCT_ID",
|
||||
// "price_consent_status": "0", // important for price_increase_consent
|
||||
// "grace_period_expires_date": "",
|
||||
// "grace_period_expires_date_ms": "",
|
||||
// "grace_period_expires_date_pst": ""
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
Reference in New Issue
Block a user