Skip to content

Commit d240b15

Browse files
Version Bump v5.0.2: swagger/oai updates + accept header fix
1 parent a1153ef commit d240b15

1 file changed

Lines changed: 143 additions & 26 deletions

File tree

test/unit/SendGridTest.php

Lines changed: 143 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function setUp()
1717

1818
public function testVersion()
1919
{
20-
$this->assertEquals(SendGrid::VERSION, '5.0.1');
20+
$this->assertEquals(SendGrid::VERSION, '5.0.2');
2121
$this->assertEquals(json_decode(file_get_contents(__DIR__ . '/../../composer.json'))->version, SendGrid::VERSION);
2222
}
2323

@@ -27,7 +27,8 @@ public function testSendGrid()
2727
$sg = new SendGrid($apiKey);
2828
$headers = array(
2929
'Authorization: Bearer '.$apiKey,
30-
'User-Agent: sendgrid/' . $sg->version . ';php'
30+
'User-Agent: sendgrid/' . $sg->version . ';php',
31+
'Accept: application/json'
3132
);
3233
$this->assertEquals($sg->client->host, "https://api.sendgrid.com");
3334
$this->assertEquals($sg->client->request_headers, $headers);
@@ -103,10 +104,57 @@ public function test_access_settings_whitelist__rule_id__delete()
103104
$this->assertEquals($response->statusCode(), 204);
104105
}
105106

107+
public function test_alerts_post()
108+
{
109+
$request_body = json_decode('{
110+
"email_to": "example@example.com",
111+
"frequency": "daily",
112+
"type": "stats_notification"
113+
}');
114+
$request_headers = array("X-Mock: 201");
115+
$response = $this->sg->client->alerts()->post($request_body, null, $request_headers);
116+
$this->assertEquals($response->statusCode(), 201);
117+
}
118+
119+
public function test_alerts_get()
120+
{
121+
$request_headers = array("X-Mock: 200");
122+
$response = $this->sg->client->alerts()->get(null, null, $request_headers);
123+
$this->assertEquals($response->statusCode(), 200);
124+
}
125+
126+
public function test_alerts__alert_id__patch()
127+
{
128+
$request_body = json_decode('{
129+
"email_to": "example@example.com"
130+
}');
131+
$alert_id = "test_url_param";
132+
$request_headers = array("X-Mock: 200");
133+
$response = $this->sg->client->alerts()->_($alert_id)->patch($request_body, null, $request_headers);
134+
$this->assertEquals($response->statusCode(), 200);
135+
}
136+
137+
public function test_alerts__alert_id__get()
138+
{
139+
$alert_id = "test_url_param";
140+
$request_headers = array("X-Mock: 200");
141+
$response = $this->sg->client->alerts()->_($alert_id)->get(null, null, $request_headers);
142+
$this->assertEquals($response->statusCode(), 200);
143+
}
144+
145+
public function test_alerts__alert_id__delete()
146+
{
147+
$alert_id = "test_url_param";
148+
$request_headers = array("X-Mock: 204");
149+
$response = $this->sg->client->alerts()->_($alert_id)->delete(null, null, $request_headers);
150+
$this->assertEquals($response->statusCode(), 204);
151+
}
152+
106153
public function test_api_keys_post()
107154
{
108155
$request_body = json_decode('{
109156
"name": "My API Key",
157+
"sample": "data",
110158
"scopes": [
111159
"mail.send",
112160
"alerts.create",
@@ -120,8 +168,9 @@ public function test_api_keys_post()
120168

121169
public function test_api_keys_get()
122170
{
171+
$query_params = json_decode('{"limit": 1}');
123172
$request_headers = array("X-Mock: 200");
124-
$response = $this->sg->client->api_keys()->get(null, null, $request_headers);
173+
$response = $this->sg->client->api_keys()->get(null, $query_params, $request_headers);
125174
$this->assertEquals($response->statusCode(), 200);
126175
}
127176

@@ -170,9 +219,9 @@ public function test_api_keys__api_key_id__delete()
170219
public function test_asm_groups_post()
171220
{
172221
$request_body = json_decode('{
173-
"description": "A group description",
174-
"is_default": false,
175-
"name": "A group name"
222+
"description": "Suggestions for products our users might like.",
223+
"is_default": true,
224+
"name": "Product Suggestions"
176225
}');
177226
$request_headers = array("X-Mock: 201");
178227
$response = $this->sg->client->asm()->groups()->post($request_body, null, $request_headers);
@@ -181,8 +230,9 @@ public function test_asm_groups_post()
181230

182231
public function test_asm_groups_get()
183232
{
233+
$query_params = json_decode('{"id": 1}');
184234
$request_headers = array("X-Mock: 200");
185-
$response = $this->sg->client->asm()->groups()->get(null, null, $request_headers);
235+
$response = $this->sg->client->asm()->groups()->get(null, $query_params, $request_headers);
186236
$this->assertEquals($response->statusCode(), 200);
187237
}
188238

@@ -237,6 +287,21 @@ public function test_asm_groups__group_id__suppressions_get()
237287
$this->assertEquals($response->statusCode(), 200);
238288
}
239289

290+
public function test_asm_groups__group_id__suppressions_search_post()
291+
{
292+
$request_body = json_decode('{
293+
"recipient_emails": [
294+
"exists1@example.com",
295+
"exists2@example.com",
296+
"doesnotexists@example.com"
297+
]
298+
}');
299+
$group_id = "test_url_param";
300+
$request_headers = array("X-Mock: 200");
301+
$response = $this->sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body, null, $request_headers);
302+
$this->assertEquals($response->statusCode(), 200);
303+
}
304+
240305
public function test_asm_groups__group_id__suppressions__email__delete()
241306
{
242307
$group_id = "test_url_param";
@@ -246,6 +311,13 @@ public function test_asm_groups__group_id__suppressions__email__delete()
246311
$this->assertEquals($response->statusCode(), 204);
247312
}
248313

314+
public function test_asm_suppressions_get()
315+
{
316+
$request_headers = array("X-Mock: 200");
317+
$response = $this->sg->client->asm()->suppressions()->get(null, null, $request_headers);
318+
$this->assertEquals($response->statusCode(), 200);
319+
}
320+
249321
public function test_asm_suppressions_global_post()
250322
{
251323
$request_body = json_decode('{
@@ -275,6 +347,14 @@ public function test_asm_suppressions_global__email__delete()
275347
$this->assertEquals($response->statusCode(), 204);
276348
}
277349

350+
public function test_asm_suppressions__email__get()
351+
{
352+
$email = "test_url_param";
353+
$request_headers = array("X-Mock: 200");
354+
$response = $this->sg->client->asm()->suppressions()->_($email)->get(null, null, $request_headers);
355+
$this->assertEquals($response->statusCode(), 200);
356+
}
357+
278358
public function test_browsers_stats_get()
279359
{
280360
$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}');
@@ -312,7 +392,7 @@ public function test_campaigns_post()
312392

313393
public function test_campaigns_get()
314394
{
315-
$query_params = json_decode('{"limit": 0, "offset": 0}');
395+
$query_params = json_decode('{"limit": 1, "offset": 1}');
316396
$request_headers = array("X-Mock: 200");
317397
$response = $this->sg->client->campaigns()->get(null, $query_params, $request_headers);
318398
$this->assertEquals($response->statusCode(), 200);
@@ -518,7 +598,7 @@ public function test_contactdb_lists__list_id__patch()
518598
$request_body = json_decode('{
519599
"name": "newlistname"
520600
}');
521-
$query_params = json_decode('{"list_id": 0}');
601+
$query_params = json_decode('{"list_id": 1}');
522602
$list_id = "test_url_param";
523603
$request_headers = array("X-Mock: 200");
524604
$response = $this->sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params, $request_headers);
@@ -527,7 +607,7 @@ public function test_contactdb_lists__list_id__patch()
527607

528608
public function test_contactdb_lists__list_id__get()
529609
{
530-
$query_params = json_decode('{"list_id": 0}');
610+
$query_params = json_decode('{"list_id": 1}');
531611
$list_id = "test_url_param";
532612
$request_headers = array("X-Mock: 200");
533613
$response = $this->sg->client->contactdb()->lists()->_($list_id)->get(null, $query_params, $request_headers);
@@ -557,7 +637,7 @@ public function test_contactdb_lists__list_id__recipients_post()
557637

558638
public function test_contactdb_lists__list_id__recipients_get()
559639
{
560-
$query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 0}');
640+
$query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 1}');
561641
$list_id = "test_url_param";
562642
$request_headers = array("X-Mock: 200");
563643
$response = $this->sg->client->contactdb()->lists()->_($list_id)->recipients()->get(null, $query_params, $request_headers);
@@ -575,7 +655,7 @@ public function test_contactdb_lists__list_id__recipients__recipient_id__post()
575655

576656
public function test_contactdb_lists__list_id__recipients__recipient_id__delete()
577657
{
578-
$query_params = json_decode('{"recipient_id": 0, "list_id": 0}');
658+
$query_params = json_decode('{"recipient_id": 1, "list_id": 1}');
579659
$list_id = "test_url_param";
580660
$recipient_id = "test_url_param";
581661
$request_headers = array("X-Mock: 204");
@@ -653,7 +733,7 @@ public function test_contactdb_recipients_count_get()
653733

654734
public function test_contactdb_recipients_search_get()
655735
{
656-
$query_params = json_decode('{"{field_name}": "test_string"}');
736+
$query_params = json_decode('{"%7Bfield_name%7D": "test_string", "{field_name}": "test_string"}');
657737
$request_headers = array("X-Mock: 200");
658738
$response = $this->sg->client->contactdb()->recipients()->search()->get(null, $query_params, $request_headers);
659739
$this->assertEquals($response->statusCode(), 200);
@@ -751,7 +831,7 @@ public function test_contactdb_segments__segment_id__patch()
751831

752832
public function test_contactdb_segments__segment_id__get()
753833
{
754-
$query_params = json_decode('{"segment_id": 0}');
834+
$query_params = json_decode('{"segment_id": 1}');
755835
$segment_id = "test_url_param";
756836
$request_headers = array("X-Mock: 200");
757837
$response = $this->sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params, $request_headers);
@@ -927,7 +1007,7 @@ public function test_mail_batch__batch_id__get()
9271007
$this->assertEquals($response->statusCode(), 200);
9281008
}
9291009

930-
public function test_mail_send_beta_post()
1010+
public function test_mail_send_post()
9311011
{
9321012
$request_body = json_decode('{
9331013
"asm": {
@@ -1018,13 +1098,8 @@ public function test_mail_send_beta_post()
10181098
"send_at": 1409348513,
10191099
"subject": "Hello, World!",
10201100
"substitutions": {
1021-
"sub": {
1022-
"%name%": [
1023-
"John",
1024-
"Jane",
1025-
"Sam"
1026-
]
1027-
}
1101+
"id": "substitutions",
1102+
"type": "object"
10281103
},
10291104
"to": [
10301105
{
@@ -1073,7 +1148,7 @@ public function test_mail_send_beta_post()
10731148
}
10741149
}');
10751150
$request_headers = array("X-Mock: 202");
1076-
$response = $this->sg->client->mail()->send()->beta()->post($request_body, null, $request_headers);
1151+
$response = $this->sg->client->mail()->send()->post($request_body, null, $request_headers);
10771152
$this->assertEquals($response->statusCode(), 202);
10781153
}
10791154

@@ -1320,7 +1395,7 @@ public function test_subusers_post()
13201395

13211396
public function test_subusers_get()
13221397
{
1323-
$query_params = json_decode('{"username": "test_string", "limit": 0, "offset": 0}');
1398+
$query_params = json_decode('{"username": "test_string", "limit": 1, "offset": 1}');
13241399
$request_headers = array("X-Mock: 200");
13251400
$response = $this->sg->client->subusers()->get(null, $query_params, $request_headers);
13261401
$this->assertEquals($response->statusCode(), 200);
@@ -1430,7 +1505,7 @@ public function test_subusers__subuser_name__monitor_delete()
14301505

14311506
public function test_subusers__subuser_name__stats_monthly_get()
14321507
{
1433-
$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 0, "sort_by_metric": "test_string", "offset": 1}');
1508+
$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}');
14341509
$subuser_name = "test_url_param";
14351510
$request_headers = array("X-Mock: 200");
14361511
$response = $this->sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params, $request_headers);
@@ -1477,7 +1552,7 @@ public function test_suppression_blocks__email__delete()
14771552

14781553
public function test_suppression_bounces_get()
14791554
{
1480-
$query_params = json_decode('{"start_time": 0, "end_time": 0}');
1555+
$query_params = json_decode('{"start_time": 1, "end_time": 1}');
14811556
$request_headers = array("X-Mock: 200");
14821557
$response = $this->sg->client->suppression()->bounces()->get(null, $query_params, $request_headers);
14831558
$this->assertEquals($response->statusCode(), 200);
@@ -1967,13 +2042,55 @@ public function test_user_webhooks_event_test_post()
19672042
$this->assertEquals($response->statusCode(), 204);
19682043
}
19692044

2045+
public function test_user_webhooks_parse_settings_post()
2046+
{
2047+
$request_body = json_decode('{
2048+
"hostname": "myhostname.com",
2049+
"send_raw": false,
2050+
"spam_check": true,
2051+
"url": "http://email.myhosthame.com"
2052+
}');
2053+
$request_headers = array("X-Mock: 201");
2054+
$response = $this->sg->client->user()->webhooks()->parse()->settings()->post($request_body, null, $request_headers);
2055+
$this->assertEquals($response->statusCode(), 201);
2056+
}
2057+
19702058
public function test_user_webhooks_parse_settings_get()
19712059
{
19722060
$request_headers = array("X-Mock: 200");
19732061
$response = $this->sg->client->user()->webhooks()->parse()->settings()->get(null, null, $request_headers);
19742062
$this->assertEquals($response->statusCode(), 200);
19752063
}
19762064

2065+
public function test_user_webhooks_parse_settings__hostname__patch()
2066+
{
2067+
$request_body = json_decode('{
2068+
"send_raw": true,
2069+
"spam_check": false,
2070+
"url": "http://newdomain.com/parse"
2071+
}');
2072+
$hostname = "test_url_param";
2073+
$request_headers = array("X-Mock: 200");
2074+
$response = $this->sg->client->user()->webhooks()->parse()->settings()->_($hostname)->patch($request_body, null, $request_headers);
2075+
$this->assertEquals($response->statusCode(), 200);
2076+
}
2077+
2078+
public function test_user_webhooks_parse_settings__hostname__get()
2079+
{
2080+
$hostname = "test_url_param";
2081+
$request_headers = array("X-Mock: 200");
2082+
$response = $this->sg->client->user()->webhooks()->parse()->settings()->_($hostname)->get(null, null, $request_headers);
2083+
$this->assertEquals($response->statusCode(), 200);
2084+
}
2085+
2086+
public function test_user_webhooks_parse_settings__hostname__delete()
2087+
{
2088+
$hostname = "test_url_param";
2089+
$request_headers = array("X-Mock: 204");
2090+
$response = $this->sg->client->user()->webhooks()->parse()->settings()->_($hostname)->delete(null, null, $request_headers);
2091+
$this->assertEquals($response->statusCode(), 204);
2092+
}
2093+
19772094
public function test_user_webhooks_parse_stats_get()
19782095
{
19792096
$query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}');

0 commit comments

Comments
 (0)