This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 376
/
WebhookControllerTest.php
62 lines (54 loc) · 1.88 KB
/
WebhookControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Osiset\ShopifyApp\Test\Controllers;
use App\Jobs\OrdersCreateJob;
use Illuminate\Support\Facades\Queue;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Test\TestCase;
use stdClass;
require_once __DIR__.'/../Stubs/OrdersCreateJob.php';
class WebhookControllerTest extends TestCase
{
public function testSuccess(): void
{
// Fake the queue
Queue::fake();
// Mock headers that match Shopify
$shop = factory($this->model)->create(['name' => 'example.myshopify.com']);
$headers = [
'HTTP_CONTENT_TYPE' => 'application/json',
'HTTP_X_SHOPIFY_SHOP_DOMAIN' => $shop->name,
'HTTP_X_SHOPIFY_HMAC_SHA256' => 'fo0+SKvmAFe9qNlV7oHL6acWZsCT36Mmahx0efMOgac=', // Matches fixture data and API secret
];
// Create a webhook call and pass in our own headers and data
$response = $this->call(
'post',
'/webhook/orders-create',
[],
[],
[],
$headers,
file_get_contents(__DIR__.'/../fixtures/webhook.json')
);
// Check it was created and job was pushed
$response->assertStatus(201);
Queue::assertPushed(OrdersCreateJob::class, function ($job) use ($shop) {
return ShopDomain::fromNative($job->shopDomain)->isSame($shop->getDomain())
&& $job->data instanceof stdClass
&& $job->data->email === 'jon@doe.ca';
});
}
public function testFailure(): void
{
// Create a webhook call and pass in our own headers and data
$response = $this->call(
'post',
'/webhook/products-create',
[],
[],
[],
[],
file_get_contents(__DIR__.'/../fixtures/webhook.json')
);
$response->assertStatus(401);
}
}