-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathEmailSubscriptionTest.php
More file actions
114 lines (97 loc) · 3.45 KB
/
EmailSubscriptionTest.php
File metadata and controls
114 lines (97 loc) · 3.45 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace SevenShores\Hubspot\Tests\Unit\Endpoints;
use PHPUnit\Framework\TestCase;
use SevenShores\Hubspot\Endpoints\EmailSubscription;
use SevenShores\Hubspot\Http\Client;
class EmailSubscriptionTest extends TestCase
{
public function test_subscription_definitions_uses_v3_definitions_endpoint()
{
$client = new RecordingClient();
$endpoint = new EmailSubscription($client);
$result = $endpoint->subscriptionDefinitions();
$this->assertSame('ok', $result);
$this->assertSame([
[
'method' => 'get',
'endpoint' => 'https://api.hubapi.com/communication-preferences/v3/definitions',
'options' => [],
'queryString' => null,
'requiresAuth' => true,
],
], $client->calls);
}
public function test_subscription_statuses_uses_v3_status_endpoint()
{
$client = new RecordingClient();
$endpoint = new EmailSubscription($client);
$result = $endpoint->subscriptionStatuses('test+tag@example.com');
$this->assertSame('ok', $result);
$this->assertSame([
[
'method' => 'get',
'endpoint' => 'https://api.hubapi.com/communication-preferences/v3/status/email/test%2Btag%40example.com',
'options' => [],
'queryString' => null,
'requiresAuth' => true,
],
], $client->calls);
}
public function test_subscribe_posts_to_v3_subscribe_endpoint()
{
$client = new RecordingClient();
$endpoint = new EmailSubscription($client);
$data = [
'emailAddress' => 'test@example.com',
'subscriptionId' => '123',
'legalBasis' => 'CONSENT_WITH_NOTICE',
];
$result = $endpoint->subscribe($data);
$this->assertSame('ok', $result);
$this->assertSame([
[
'method' => 'post',
'endpoint' => 'https://api.hubapi.com/communication-preferences/v3/subscribe',
'options' => ['json' => $data],
'queryString' => null,
'requiresAuth' => true,
],
], $client->calls);
}
public function test_unsubscribe_posts_to_v3_unsubscribe_endpoint()
{
$client = new RecordingClient();
$endpoint = new EmailSubscription($client);
$data = [
'emailAddress' => 'test@example.com',
'subscriptionId' => '123',
'legalBasis' => 'CONSENT_WITH_NOTICE',
];
$result = $endpoint->unsubscribe($data);
$this->assertSame('ok', $result);
$this->assertSame([
[
'method' => 'post',
'endpoint' => 'https://api.hubapi.com/communication-preferences/v3/unsubscribe',
'options' => ['json' => $data],
'queryString' => null,
'requiresAuth' => true,
],
], $client->calls);
}
}
class RecordingClient extends Client
{
public $calls = [];
public function request(string $method, string $endpoint, array $options = [], $query_string = null, bool $requires_auth = true)
{
$this->calls[] = [
'method' => $method,
'endpoint' => $endpoint,
'options' => $options,
'queryString' => $query_string,
'requiresAuth' => $requires_auth,
];
return 'ok';
}
}