Skip to content

Commit 4bcfe50

Browse files
committed
Merge remote-tracking branch 'origin/update-tests-api-spec' into updated-coding-standards
2 parents 6fb381b + 362104b commit 4bcfe50

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

tests/wpunit/APITest.php

+30-23
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,9 @@ public function testGetGrowthStatsWithStartDate()
756756
$this->assertArrayHasKey('ending', $result['stats']);
757757

758758
// Assert start and end dates were honored.
759-
$this->assertEquals($result['stats']['starting'], $starting->format('Y-m-d') . 'T00:00:00-04:00');
760-
$this->assertEquals($result['stats']['ending'], $ending->format('Y-m-d') . 'T23:59:59-04:00');
759+
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P'); // Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
760+
$this->assertEquals($result['stats']['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
761+
$this->assertEquals($result['stats']['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
761762
}
762763

763764
/**
@@ -790,8 +791,9 @@ public function testGetGrowthStatsWithEndDate()
790791
$this->assertArrayHasKey('ending', $result['stats']);
791792

792793
// Assert start and end dates were honored.
793-
$this->assertEquals($result['stats']['starting'], $starting->format('Y-m-d') . 'T00:00:00-04:00');
794-
$this->assertEquals($result['stats']['ending'], $ending->format('Y-m-d') . 'T23:59:59-04:00');
794+
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P'); // Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
795+
$this->assertEquals($result['stats']['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
796+
$this->assertEquals($result['stats']['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
795797
}
796798

797799
/**
@@ -1249,7 +1251,7 @@ public function testGetFormSubscriptionsWithBouncedSubscriberState()
12491251
*/
12501252
public function testGetFormSubscriptionsWithAddedAfterParam()
12511253
{
1252-
$date = new \DateTime('2024-01-01');
1254+
$date = new \DateTime('2022-01-01');
12531255
$result = $this->api->get_form_subscriptions(
12541256
(int) $_ENV['CONVERTKIT_API_FORM_ID'], // Form ID.
12551257
'active', // Subscriber state.
@@ -1312,7 +1314,7 @@ public function testGetFormSubscriptionsWithAddedBeforeParam()
13121314
*/
13131315
public function testGetFormSubscriptionsWithCreatedAfterParam()
13141316
{
1315-
$date = new \DateTime('2024-01-01');
1317+
$date = new \DateTime('2022-01-01');
13161318
$result = $this->api->get_form_subscriptions(
13171319
(int) $_ENV['CONVERTKIT_API_FORM_ID'], // Form ID.
13181320
'active', // Subscriber state.
@@ -2272,7 +2274,7 @@ public function testGetSequenceSubscriptionsWithBouncedSubscriberState()
22722274
*/
22732275
public function testGetSequenceSubscriptionsWithAddedAfterParam()
22742276
{
2275-
$date = new \DateTime('2024-01-01');
2277+
$date = new \DateTime('2022-01-01');
22762278
$result = $this->api->get_sequence_subscriptions(
22772279
$_ENV['CONVERTKIT_API_SEQUENCE_ID'], // Sequence ID.
22782280
'active', // Subscriber state.
@@ -2335,7 +2337,7 @@ public function testGetSequenceSubscriptionsWithAddedBeforeParam()
23352337
*/
23362338
public function testGetSequenceSubscriptionsWithCreatedAfterParam()
23372339
{
2338-
$date = new \DateTime('2024-01-01');
2340+
$date = new \DateTime('2022-01-01');
23392341
$result = $this->api->get_sequence_subscriptions(
23402342
$_ENV['CONVERTKIT_API_SEQUENCE_ID'], // Sequence ID.
23412343
'active', // Subscriber state.
@@ -2441,7 +2443,7 @@ public function testGetSequenceSubscriptionsPagination()
24412443

24422444
// Assert has_previous_page and has_next_page are correct.
24432445
$this->assertTrue($result['pagination']['has_previous_page']);
2444-
$this->assertTrue($result['pagination']['has_next_page']);
2446+
$this->assertFalse($result['pagination']['has_next_page']);
24452447

24462448
// Use pagination to fetch previous page.
24472449
$result = $this->api->get_sequence_subscriptions(
@@ -2654,7 +2656,7 @@ public function testCreateTagBlank()
26542656
}
26552657

26562658
/**
2657-
* Test that create_tag() returns a WP_Error when creating
2659+
* Test that create_tag() returns the expected data when creating
26582660
* a tag that already exists.
26592661
*
26602662
* @since 1.0.0
@@ -2664,8 +2666,12 @@ public function testCreateTagBlank()
26642666
public function testCreateTagThatExists()
26652667
{
26662668
$result = $this->api->create_tag($_ENV['CONVERTKIT_API_TAG_NAME']);
2667-
$this->assertInstanceOf(WP_Error::class, $result);
2668-
$this->assertEquals($result->get_error_code(), $this->errorCode);
2669+
2670+
// Assert response contains correct data.
2671+
$this->assertArrayHasKey('id', $result['tag']);
2672+
$this->assertArrayHasKey('name', $result['tag']);
2673+
$this->assertArrayHasKey('created_at', $result['tag']);
2674+
$this->assertEquals($result['tag']['name'], $_ENV['CONVERTKIT_API_TAG_NAME']);
26692675
}
26702676

26712677
/**
@@ -2728,14 +2734,13 @@ public function testCreateTagsBlank()
27282734
'',
27292735
]
27302736
);
2731-
2732-
// Assert failures.
2733-
$this->assertCount(2, $result['failures']);
2737+
$this->assertInstanceOf(WP_Error::class, $result);
2738+
$this->assertEquals($result->get_error_code(), $this->errorCode);
27342739
}
27352740

27362741
/**
2737-
* Test that create_tags() returns a WP_Error when creating
2738-
* tags that already exists.
2742+
* Test that create_tags() returns the expected data when creating
2743+
* tags that already exist.
27392744
*
27402745
* @since 2.0.0
27412746
*
@@ -2750,8 +2755,10 @@ public function testCreateTagsThatExist()
27502755
]
27512756
);
27522757

2753-
// Assert failures.
2754-
$this->assertCount(2, $result['failures']);
2758+
// Assert existing tags are returned.
2759+
$this->assertCount(2, $result['tags']);
2760+
$this->assertEquals($result['tags'][1]['name'], $_ENV['CONVERTKIT_API_TAG_NAME']);
2761+
$this->assertEquals($result['tags'][0]['name'], $_ENV['CONVERTKIT_API_TAG_NAME_2']);
27552762
}
27562763

27572764
/**
@@ -3127,7 +3134,7 @@ public function testGetTagSubscriptionsWithBouncedSubscriberState()
31273134
*/
31283135
public function testGetTagSubscriptionsWithTaggedAfterParam()
31293136
{
3130-
$date = new \DateTime('2024-01-01');
3137+
$date = new \DateTime('2022-01-01');
31313138
$result = $this->api->get_tag_subscriptions(
31323139
(int) $_ENV['CONVERTKIT_API_TAG_ID'], // Tag ID.
31333140
'active', // Subscriber state.
@@ -3190,7 +3197,7 @@ public function testGetTagSubscriptionsWithTaggedBeforeParam()
31903197
*/
31913198
public function testGetTagSubscriptionsWithCreatedAfterParam()
31923199
{
3193-
$date = new \DateTime('2024-01-01');
3200+
$date = new \DateTime('2022-01-01');
31943201
$result = $this->api->get_tag_subscriptions(
31953202
(int) $_ENV['CONVERTKIT_API_TAG_ID'], // Tag ID.
31963203
'active', // Subscriber state.
@@ -3450,7 +3457,7 @@ public function testGetSubscribersWithBouncedSubscriberState()
34503457
*/
34513458
public function testGetSubscribersWithCreatedAfterParam()
34523459
{
3453-
$date = new \DateTime('2024-01-01');
3460+
$date = new \DateTime('2022-01-01');
34543461
$result = $this->api->get_subscribers(
34553462
'active', // Subscriber state.
34563463
'', // Email address.
@@ -3507,7 +3514,7 @@ public function testGetSubscribersWithCreatedBeforeParam()
35073514
*/
35083515
public function testGetSubscribersWithUpdatedAfterParam()
35093516
{
3510-
$date = new \DateTime('2024-01-01');
3517+
$date = new \DateTime('2022-01-01');
35113518
$result = $this->api->get_subscribers(
35123519
'active', // Subscriber state.
35133520
'', // Email address.

0 commit comments

Comments
 (0)